This repository has been archived by the owner on Oct 30, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
odeskJobsSearcher.py
125 lines (95 loc) · 4.02 KB
/
odeskJobsSearcher.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
import odesk
import json
import datetime
import dateutil.parser
import json
#pip install python-dateutil
#pip install python-odesk
#API keys of your application (this script)
#Get it from https://www.odesk.com/services/api/keys
public_key = "todo"
secret_key = "todo"
#Tokens for user that authorized this app
#Use odeskJobsSearcher_authentication_helper.py for getting this tokens
oauth_access_token = "todo"
oauth_access_token_secret = "todo"
#Job search parameters, tune it as needed
#(reference: https://developers.odesk.com/?lang=python#jobs_search-for-jobs)
max_date_created_offset = 7 # maximum age of job (in days)
job_search_parameter = {'job_status': 'open',
'days_posted': 5,
'budget': '1000',
'client_hires':'15',
'skills': 'python'}
class odeskJobsSearcher(NebriOS):
listens_to = ['get_odesk_jobs']
schedule = "0 0 * * *" # daily
def check_date_is_within_offset(self, date, offset):
"""Checks if given date is withing given offset of
days from today (in past)"""
smallest_allowed_date = datetime.date.today() - datetime.timedelta(
days=offset)
job_date = dateutil.parser.parse(date).date()
return job_date >= smallest_allowed_date
def convert_job(self, job):
"""Filters unneeded fields from given job, and
returns job with only title, url and date_created fields"""
try:
converted_job = {'title':job['title'],
'url':job['url'],
'date_created':job['date_created']}
except Exception, e:
print "Job conversion error. Looks like API problem"
raise e
return converted_job
def get_jobs_list(self, client, jobs_parameter):
"""Searches for all available jobs on oDesk accordingly
to given jobs_parameter search query, then filters
out too old jobs and returns title, url and
date_created fields for each job"""
jobs_api_response = []
current_page_offset = 0
max_page_size = 100
while True:
try:
current_jobs_api_response = client.provider_v2.search_jobs(
jobs_parameter,
page_offset = current_page_offset,
page_size = max_page_size)
except Exception, e:
print "API or http error occured, can't do much there :-("
raise e
jobs_api_response += current_jobs_api_response
#check for last page
if len(current_jobs_api_response) < max_page_size:
break
#update offset to match next page
current_page_offset += max_page_size
try:
#filter jobs with date_created > max_date_created
#get only needed data from jobs
jobs = [self.convert_job(i) for i in jobs_api_response if
self.check_date_is_within_offset(i['date_created'],
max_date_created_offset)]
except Exception, e:
print "API or https error occured, or there is API change"
raise e
return jobs
def jobs_search(self):
client = odesk.Client(public_key, secret_key,
oauth_access_token=oauth_access_token,
oauth_access_token_secret=oauth_access_token_secret)
jobs = self.get_jobs_list(client=client,
jobs_parameter=job_search_parameter)
return jobs
def check(self):
jobs = self.jobs_search()
#check passes only if there is at least one job found
if len(jobs) > 0:
self.jobs = json.dumps(jobs)
return True
return False
def action(self):
#update shared variable
shared.compatible_odesk_jobs = self.jobs
return