-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
54 lines (41 loc) · 1.18 KB
/
main.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
import json
import urllib2
from bs4 import BeautifulSoup
from job import Job
from utils import BadData, add_url_params
GLASSDOOR_URL = 'http://api.glassdoor.com/api/api.htm'
KEY = 'bBT8AIvltt9'
PID = '235446'
def get(params):
"""Modified GET request.
Args:
params(dict): Dictionary of query parameters.
Returns:
JSON encoded dictionary.
"""
params.update({
'v': '1',
'format': 'json',
'action': 'jobs',
'userip': '192.168.43.42',
'useragent': 'Mozilla'
})
url = add_url_params(GLASSDOOR_URL, params)
header = {'User-Agent': 'Mozilla/5.0'}
req = urllib2.Request(url, headers=header)
response = urllib2.urlopen(req)
soup = BeautifulSoup(response, "html.parser")
return json.loads(str(soup))
def main():
"""Operation headquarters."""
# query = raw_input('What kind of job are you looking for? ')
params = {'t.k': KEY, 't.p': PID, 'q': 'developer'}
try:
json = get(params)
except urllib2.HTTPError, err:
raise err
else:
jobs = [Job(j) for j in json['response']['employers']]
import pdb; pdb.set_trace()
if __name__ == '__main__':
main()