-
-
Notifications
You must be signed in to change notification settings - Fork 42
/
utils.py
265 lines (235 loc) · 8.6 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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
import math,constants,config
from typing import List
import time
from selenium.webdriver.firefox.options import Options
def browserOptions():
options = Options()
firefoxProfileRootDir = config.firefoxProfileRootDir
options.add_argument("--start-maximized")
options.add_argument("--ignore-certificate-errors")
options.add_argument('--no-sandbox')
options.add_argument("--disable-extensions")
options.add_argument('--disable-gpu')
if(config.headless):
options.add_argument("--headless")
options.add_argument("--disable-blink-features")
options.add_argument("--disable-blink-features=AutomationControlled")
options.add_argument("--incognito")
options.add_argument("-profile")
options.add_argument(firefoxProfileRootDir)
return options
def prRed(prt):
print(f"\033[91m{prt}\033[00m")
def prGreen(prt):
print(f"\033[92m{prt}\033[00m")
def prYellow(prt):
print(f"\033[93m{prt}\033[00m")
def getUrlDataFile():
urlData = ""
try:
file = open('data/urlData.txt', 'r')
urlData = file.readlines()
except FileNotFoundError:
text = "FileNotFound:urlData.txt file is not found. Please run ./data folder exists and check config.py values of yours. Then run the bot again"
prRed(text)
return urlData
def jobsToPages(numOfJobs: str) -> int:
number_of_pages = 1
if (' ' in numOfJobs):
spaceIndex = numOfJobs.index(' ')
totalJobs = (numOfJobs[0:spaceIndex])
totalJobs_int = int(totalJobs.replace(',', ''))
number_of_pages = math.ceil(totalJobs_int/constants.jobsPerPage)
if (number_of_pages > 40 ): number_of_pages = 40
else:
number_of_pages = int(numOfJobs)
return number_of_pages
def urlToKeywords(url: str) -> List[str]:
keywordUrl = url[url.index("keywords=")+9:]
keyword = keywordUrl[0:keywordUrl.index("&") ]
locationUrl = url[url.index("location=")+9:]
location = locationUrl[0:locationUrl.index("&") ]
return [keyword,location]
def writeResults(text: str):
timeStr = time.strftime("%Y%m%d")
fileName = "Applied Jobs DATA - " +timeStr + ".txt"
try:
with open("data/" +fileName, encoding="utf-8" ) as file:
lines = []
for line in file:
if "----" not in line:
lines.append(line)
with open("data/" +fileName, 'w' ,encoding="utf-8") as f:
f.write("---- Applied Jobs Data ---- created at: " +timeStr+ "\n" )
f.write("---- Number | Job Title | Company | Location | Work Place | Posted Date | Applications | Result " +"\n" )
for line in lines:
f.write(line)
f.write(text+ "\n")
except:
with open("data/" +fileName, 'w', encoding="utf-8") as f:
f.write("---- Applied Jobs Data ---- created at: " +timeStr+ "\n" )
f.write("---- Number | Job Title | Company | Location | Work Place | Posted Date | Applications | Result " +"\n" )
f.write(text+ "\n")
def printInfoMes(bot:str):
prYellow("ℹ️ " +bot+ " is starting soon... ")
def donate(self):
prYellow('If you like the project, please support me so that i can make more such projects, thanks!')
try:
self.driver.get('https://commerce.coinbase.com/checkout/576ee011-ba40-47d5-9672-ef7ad29b1e6c')
except Exception as e:
prRed("Error in donate: " +str(e))
class LinkedinUrlGenerate:
def generateUrlLinks(self):
path = []
for location in config.location:
for keyword in config.keywords:
url = constants.linkJobUrl + "?f_AL=true&keywords=" +keyword+self.jobType()+self.remote()+self.checkJobLocation(location)+self.jobExp()+self.datePosted()+self.salary()+self.sortBy()
path.append(url)
return path
def checkJobLocation(self,job):
jobLoc = "&location=" +job
match job.casefold():
case "asia":
jobLoc += "&geoId=102393603"
case "europe":
jobLoc += "&geoId=100506914"
case "northamerica":
jobLoc += "&geoId=102221843&"
case "southamerica":
jobLoc += "&geoId=104514572"
case "australia":
jobLoc += "&geoId=101452733"
case "africa":
jobLoc += "&geoId=103537801"
return jobLoc
def jobExp(self):
jobtExpArray = config.experienceLevels
firstJobExp = jobtExpArray[0]
jobExp = ""
match firstJobExp:
case "Internship":
jobExp = "&f_E=1"
case "Entry level":
jobExp = "&f_E=2"
case "Associate":
jobExp = "&f_E=3"
case "Mid-Senior level":
jobExp = "&f_E=4"
case "Director":
jobExp = "&f_E=5"
case "Executive":
jobExp = "&f_E=6"
for index in range (1,len(jobtExpArray)):
match jobtExpArray[index]:
case "Internship":
jobExp += "%2C1"
case "Entry level":
jobExp +="%2C2"
case "Associate":
jobExp +="%2C3"
case "Mid-Senior level":
jobExp += "%2C4"
case "Director":
jobExp += "%2C5"
case "Executive":
jobExp +="%2C6"
return jobExp
def datePosted(self):
datePosted = ""
match config.datePosted[0]:
case "Any Time":
datePosted = ""
case "Past Month":
datePosted = "&f_TPR=r2592000&"
case "Past Week":
datePosted = "&f_TPR=r604800&"
case "Past 24 hours":
datePosted = "&f_TPR=r86400&"
return datePosted
def jobType(self):
jobTypeArray = config.jobType
firstjobType = jobTypeArray[0]
jobType = ""
match firstjobType:
case "Full-time":
jobType = "&f_JT=F"
case "Part-time":
jobType = "&f_JT=P"
case "Contract":
jobType = "&f_JT=C"
case "Temporary":
jobType = "&f_JT=T"
case "Volunteer":
jobType = "&f_JT=V"
case "Intership":
jobType = "&f_JT=I"
case "Other":
jobType = "&f_JT=O"
for index in range (1,len(jobTypeArray)):
match jobTypeArray[index]:
case "Full-time":
jobType += "%2CF"
case "Part-time":
jobType +="%2CP"
case "Contract":
jobType +="%2CC"
case "Temporary":
jobType += "%2CT"
case "Volunteer":
jobType += "%2CV"
case "Intership":
jobType +="%2CI"
case "Other":
jobType +="%2CO"
jobType += "&"
return jobType
def remote(self):
remoteArray = config.remote
firstJobRemote = remoteArray[0]
jobRemote = ""
match firstJobRemote:
case "On-site":
jobRemote = "f_WT=1"
case "Remote":
jobRemote = "f_WT=2"
case "Hybrid":
jobRemote = "f_WT=3"
for index in range (1,len(remoteArray)):
match remoteArray[index]:
case "On-site":
jobRemote += "%2C1"
case "Remote":
jobRemote += "%2C2"
case "Hybrid":
jobRemote += "%2C3"
return jobRemote
def salary(self):
salary = ""
match config.salary[0]:
case "$40,000+":
salary = "f_SB2=1&"
case "$60,000+":
salary = "f_SB2=2&"
case "$80,000+":
salary = "f_SB2=3&"
case "$100,000+":
salary = "f_SB2=4&"
case "$120,000+":
salary = "f_SB2=5&"
case "$140,000+":
salary = "f_SB2=6&"
case "$160,000+":
salary = "f_SB2=7&"
case "$180,000+":
salary = "f_SB2=8&"
case "$200,000+":
salary = "f_SB2=9&"
return salary
def sortBy(self):
sortBy = ""
match config.sort[0]:
case "Recent":
sortBy = "sortBy=DD"
case "Relevent":
sortBy = "sortBy=R"
return sortBy