Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Job alerts
import requests,json,sys,os
"""
Usage: python3 jobs.py company_name job_keyword
If you want every minute update: `crontab -e` > `* * * * * python3 jobs.py company_name job_keyword`
"""
companyName = sys.argv[1]
jobUrl = 'https://api.greenhouse.io/v1/boards/{0}/jobs?content=true'.format(companyName)
def sendSlackMessage(message):
slackWebhook = 'https://hooks.slack.com/services/XXXXXX/XXXXX/XXXXXXXX'
readyMessage = {'text':message}
sendMessage = requests.post(slackWebhook, data=json.dumps(readyMessage), headers={'Content-Type':'application/json'})
def getJobs(searchKey):
s = requests.get(jobUrl).json()
titleSearch = searchKey
jobs = {"titles":[],"url":[]}
for req in s['jobs']:
jobsUrl = req['absolute_url']
title = req['title']
if titleSearch in title:
jobs['titles'].append(title)
jobs['url'].append(jobsUrl)
return jobs
def updateAddFile(jobsDict):
f = open('myjobs-{0}.txt'.format(companyName),'w')
json.dump(jobsDict, f)
f.close()
def compareJobs(jobsDict):
f = open('myjobs-{0}.txt'.format(companyName),'r')
jobs = json.load(f) # jobs mapping for saved txt file
currentJobsSet = set(jobsDict['titles'])
fromFileJobsSet = set(jobs['titles'])
changeSet = currentJobsSet.difference(fromFileJobsSet)
if len(changeSet) > 0:
message = 'New job post alerts for *{0}*:\n'.format(companyName)
for changes in changeSet:
indexInCurrent = jobsDict['titles'].index(changes)
message += '* {0} - {1}\n'.format(changes, jobsDict['url'][indexInCurrent])
sendSlackMessage(message)
updateAddFile(jobsDict)
def main():
foundJobs = getJobs(sys.argv[2])
#lets check if if file exists
exists = os.path.isfile('myjobs-{0}.txt'.format(companyName))
if exists:
compareJobs(foundJobs)
else:
updateAddFile(foundJobs)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.