forked from peviitor-ro/scrapers_david
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
61 lines (47 loc) · 1.8 KB
/
utils.py
File metadata and controls
61 lines (47 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import requests
import os
import json
def create_job(**kwargs):
job = {}
job.update(kwargs)
return job
def clean(version, company, apikey):
apikey = os.environ.get(apikey)
content_type = "application/x-www-form-urlencoded"
requests.post("https://api.peviitor.ro/v" + str(version) + "/clean/", headers={"apikey": apikey, "Content-Type": content_type}, data={"company": company})
def update(version, apikey, data):
apikey = os.environ.get(apikey)
content_type = "application/json"
requests.post("https://api.peviitor.ro/v" + str(version) + "/update/", headers={"apikey": apikey, "Content-Type": content_type}, json=data)
def dataset(company, data):
content_type = "application/json"
requests.post(f"https://dev.laurentiumarian.ro/dataset/based_scraper_py/{company.lower()}.py/", headers={"Content-Type": content_type}, json={"data": len(data)})
def publish(version, company, data, apikey):
clean(version, company, apikey)
update(version, apikey, data)
dataset(company, data)
def publish_logo(company, logo_url):
content_type = "application/json"
requests.post("https://api.peviitor.ro/v1/logo/add/", headers={"Content-Type": content_type}, json=[{
"id": company,
"logo": logo_url
}])
def show_jobs(data):
print(json.dumps(data, indent=4))
def translate_city(city):
cities = {
# This is general for all scrapers
"bucharest": "Bucuresti",
"cluj": "Cluj-Napoca",
"cristești, mureș":"Cristesti",
"alba": "Alba Iulia",
############################
}
if cities.get(city.lower()):
return cities.get(city.lower())
else:
return city
def acurate_city_and_county(**kwargs):
city_and_county = {}
city_and_county.update(kwargs)
return city_and_county