-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjob.py
63 lines (53 loc) · 1.81 KB
/
job.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
import tweepy
import requests
import json
import time
import cPickle as pickle
def tweepy_access():
''' Tweepy API authentication. Consumer key and access key have been omitted. Please set these variables with values for your twitter handle from app.twitter.com '''
consumer_key = '#############'
consumer_secret = '#############'
access_token = '#############'
access_token_secret = '#############'
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
return api
def retrieve_jobs():
''' returns python related jobs '''
keyword = "python"
link = "https://jobs.github.com/positions.json?description=" + keyword
r = requests.get(link)
jobs = json.loads(r.text)
return jobs
def load_ids():
''' returns job id's that are already tweeted out to avoid repetition '''
x = open('jobs.p', 'rb')
ids = pickle.load(x)
x.close()
return ids
api = tweepy_access()
ids = set()
# Try loading the jobs.p file to see if it exists. If not, we pickle the empty set, without this you may recieve errors. This is where jobs.p is created as well.
try:
foo = pickle.load(open("jobs.p", "rb"))
except (OSError, IOError) as e:
f = open('jobs.p', 'wb')
pickle.dump(ids, f, -1)
f.close()
#Posts any new listings, refreshed every 2 hours
while True:
ids = load_ids()
jobs = retrieve_jobs()
for job in jobs:
id = job['id']
if id in ids:
break
else:
f = open('jobs.p', 'wb')
ids.add(id)
pickle.dump(ids, f, -1)
f.close()
message = 'Apply Now: ' + job['title'] + ' in ' + job['location'] + '\n'+ job['url'] + '\n'
api.update_status(status=message)
time.sleep(7200)