-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.py
95 lines (71 loc) · 2.42 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
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
from datetime import datetime
import base64
import hashlib
import upwork
import json
from time import sleep
import os
import webbrowser
JOB_QUERY_LOW_END = dict(
skills=['python'],
budget='-500',
duration=['week', 'month', 'ongoing']
)
JOB_QUERY_HIGH_END = dict(
skills=['python'],
budget='500-',
duration=['month', 'ongoing', 'semester', 'quarter']
)
def encode(ele):
return base64.b64encode(hashlib.sha1(str(ele)).digest())
def get_client():
cred_file = open('credentials.json', 'r')
cred_json = json.load(cred_file)
cred_file.close()
public_key = cred_json['public_key']
secret_key = cred_json['secret_key']
upwork_client = upwork.Client(public_key, secret_key)
auth_url = upwork_client.auth.get_authorize_url()
# Opens a new tab in default web browser
webbrowser.open(url=auth_url, autoraise=True, new=2)
print 'Go to the mentioned URL : {}'.format(auth_url)
verifier = raw_input('Enter Verifier: ')
(token, token_secret) = upwork_client.auth.get_access_token(verifier)
upwork_client = upwork.Client(
public_key, secret_key,
oauth_access_token=token,
oauth_access_token_secret=token_secret)
return upwork_client
if __name__ == '__main__':
IGNORE_INITIAL_JOBS = True
job_query = JOB_QUERY_LOW_END
NOTIFICATION_FILE = 'notification.wav'
client = get_client()
prev_jobs = set()
if IGNORE_INITIAL_JOBS:
jobs = client.provider_v2.search_jobs(job_query)
for job in jobs:
prev_jobs.add(encode(job))
while True:
# Get all latest jobs
print '\nGetting Jobs at {} ...\n'.format(
datetime.now().strftime('%H:%M'))
jobs = client.provider_v2.search_jobs(job_query)
current_jobs = set()
# Iterate every job
for job in jobs:
# Generate a hash
uid = encode(job)
current_jobs.add(uid)
# Check if not viewed; new job
if uid not in prev_jobs:
prev_jobs.add(uid)
os.system('aplay {}'.format(NOTIFICATION_FILE))
print ('Time : {}\nJob Title : {}\nURL : {}\n'.format(
datetime.now().strftime('%H:%M'),
job['title'], job['url']
))
webbrowser.open(url=job['url'], autoraise=True, new=2)
prev_jobs = current_jobs
# 1.5 minutes rest
sleep(90)