-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculator.py
119 lines (95 loc) · 4.81 KB
/
calculator.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
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
from re import findall, match, IGNORECASE
from argparse import ArgumentParser
professions = ['net', 'analytics', 'architecture', 'c', 'data', 'devops', 'erp', 'game', 'go', 'html', 'admin', 'java', 'javascript', 'mobile', 'php', 'pm', 'python', 'ruby', 'scala', 'security', 'support', 'testing', 'ux']
experience = ['junior', 'mid', 'senior']
employment = ['b2b', 'permanent', 'mandate_contract']
parser = ArgumentParser()
parser.add_argument('--prof', choices=professions, help='Profession')
parser.add_argument('--exp', choices=experience, help='Experience level')
parser.add_argument('--emp', choices=employment, help='Type of employment')
args = parser.parse_args()
prof = '' if not args.prof else args.prof # You can set is as permanent value. Use one of values in professions
exp = '' if not args.exp else args.exp # You can set is as permanent value. Use one of values in experience
emp = '' if not args.emp else args.emp # You can set is as permanent value. Use one of values in employment
def get_profession():
global prof
while prof not in professions:
user = input("Type key word of your profession: ")
guess = [p for p in professions if match(f'.*({user}).*', p, flags=IGNORECASE)]
if len(guess) == 0:
print("Nothing found! Please try again or press enter to display all available professions")
elif len(guess) == 1:
if input(f"Do you mean {guess[0].title()}? y/n: ").lower() in ['y', 'yes']:
prof = guess[0]
break
elif len(guess) > 1:
print('\n'.join(list(map(lambda x: f'{guess.index(x)+1}: {x.title()}', guess))))
i = input("\nIf You mean one of them, type it ID here, or anything else to try again: ")
if i in list(map(str, range(1, len(guess)+1))):
prof = guess[int(i)-1]
print(f"\nYour role is: {prof}")
break
else:
print("Wrong ID!")
def get_experience():
global exp
while exp not in experience:
print('\n'.join(list(map(lambda x: f'{experience.index(x) + 1}: {x}', experience))).title())
i = int(input(f"Type one ID or 0 to select all: "))
if i in range(1, len(experience)+1):
exp = experience[int(i) - 1]
print(f"\nSelected experience is: {exp.title()}\n")
break
elif i == 0:
print(f"\nSelected experience is: {', '.join(experience).title()}\n")
break
def get_employment():
global emp
while emp not in employment:
print('\n'.join(list(map(lambda x: f'{employment.index(x) + 1}: {x}', employment))).title())
i = int(input(f"Type one ID or 0 to select all: "))
if i in range(1, len(employment)+1):
emp = employment[int(i) - 1]
print(f"\nSelected employment is: {emp.title()}\n")
break
elif i == 0:
print(f"\nSelected employment is: {', '.join(employment).title()}\n")
break
get_profession()
get_experience()
get_employment()
# Prepare url
url = f"https://justjoin.it/"
url += f'all/{prof}' if prof else ''
url += f'all/all/{exp}' if exp and not prof else (f'/{exp}' if exp else '')
url += f'?employmentType={emp}&tab=with-salary' if emp else '?tab=with-salary'
# Prepare bowser
options = Options()
options.add_argument("--headless")
options.add_experimental_option('excludeSwitches', ['enable-logging']) # Disable annoying alert 'DevTools listening...'
driver = webdriver.Chrome(service=Service(), options=options) # Replace Service() to Service('/path/to/chromedriver')
driver.get(url)
# Find salary in page source
offers = findall(r"[0-9]{1,2}.?[0-9]?k - [0-9]{1,2}.?[0-9]?k [A-Z]{3}", driver.page_source)
if len(offers) == 0:
print(f"Sorry, no offers at the moment. For {exp} {prof} on {emp} employment type")
exit()
currency = findall(r"[A-Z]{3}", offers[0])[0]
driver.close()
# Get smallest, biggest and average salary
offer_min = []
offer_max = []
offer_avg = []
for o in offers:
offer = o.replace('k ', '').replace(f'{currency}', '').split('-')
offer_min.append(float(offer[0])*1000)
offer_max.append(float(offer[1])*1000)
offer_avg.append((float(offer[0]) + float(offer[1])) / 2 * 1000)
print(f"Result for {exp} {prof} on {emp} employment type:\n")
print(f"Average salary brackets: {round(sum(offer_min)/len(offer_min))} - {round(sum(offer_max)/len(offer_max))} {currency}")
print(f"Average salary: {round(sum(offer_avg)/len(offer_avg))} {currency}")
print(f"Smallest salary: {round(min(offer_min))} {currency}")
print(f"Biggest salary: {round(max(offer_max))} {currency}")