-
Notifications
You must be signed in to change notification settings - Fork 11
/
utils.py
142 lines (107 loc) · 3.86 KB
/
utils.py
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import requests
import os
import json
from dotenv import load_dotenv
load_dotenv()
domain = os.environ.get("DOMAIN")
def get_token():
"""
Returnează token-ul necesar pentru a face request-uri către API.
:return: token-ul necesar pentru a face request-uri către API
"""
endpoint = os.environ.get("TOKEN_ROUTE")
email = os.environ.get("EMAIL")
headers = {"User-Agent": "Mozilla/5.0"}
url = f"{domain}{endpoint}"
response = requests.post(url, json={"email": email}, headers=headers)
return response.json()["access"]
def create_job(**kwargs):
job = {}
job.update(kwargs)
return job
def publish_or_update(data):
if not data:
print("No jobs Available")
return
route = os.environ.get("ADD_JOBS_ROUTE")
url = f"{domain}{route}"
token = os.environ.get("TOKEN") if os.environ.get("TOKEN") else get_token()
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {token}", "User-Agent": "Mozilla/5.0"}
res = requests.post(url, headers=headers, json=data)
status_code = res.status_code
if status_code == 200:
company = data[0].get("company")
total_jobs = len(data)
print(f"Successfully added {total_jobs} jobs for {company} company.")
else:
raise Exception(f"Failed to add jobs. Status code: {status_code}")
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):
city = city.replace(" ", "_")
cities = {
# This is general for all scrapers
"bucharest": "Bucuresti",
"cluj": "Cluj-Napoca",
# This is for Arabesque Scraper
"targul-mures": "Targu-Mures",
"militari": "Bucuresti",
############################
# This is for Vodafone Scraper
"cluj_napoca": "Cluj-Napoca",
"targu_mures": "Targu-Mures",
"pipera": "Bucuresti",
############################
# This is for ppt
"campulung_muscel": "Campulung",
# This is for Strabag
"petrobrazi": "Ploiesti",
# This is for CARTOFISSERIE
"Satu-Mare": "Satu Mare",
"Piatra_Neamt": "Piatra Neamt",
}
if cities.get(city.lower()):
return cities.get(city.lower())
else:
return city.replace("_", " ")
def acurate_city_and_county(**kwargs):
"""
Returns a dictionary containing accurate city and county information.
Keyword Arguments:
**kwargs -- key-value pairs representing city and county information
Returns:
A dictionary containing accurate city and county information.
"""
city_and_county = {}
if kwargs:
city_and_county.update(kwargs)
else:
city_and_county = {
"Satu_Mare": {"city": "Satu Mare", "county": "Satu Mare"},
"Iasi": {"city": "Iasi", "county": "Iasi"},
"Piatra_Neamt": {"city": "Piatra-Neamt", "county": "Neamt"},
"Ramnicu_Valcea": {"city": "Ramnicu Valcea", "county": "Valcea"},
}
return city_and_county
def get_jobtype(sentence, **kwargs):
"""
Get the job types mentioned in a sentence.
Args:
sentence (str): The sentence to analyze.
**kwargs: Additional keyword arguments.
jobs_typse (list): Additional job types to consider.
Returns:
list: A list of job types mentioned in the sentence.
"""
jobs_typse = ["on-site", "remote", "hybrid"]
jobs_typse.extend(kwargs.get("jobs_typse", []))
sentence = sentence.lower().replace("_", "-").replace("onsite", "on-site")
types = [jobtype for jobtype in jobs_typse if jobtype in sentence.lower()]
return list(set(types))