Skip to content

Instantly share code, notes, and snippets.

@rojan-rijal
Last active June 2, 2023 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rojan-rijal/6919ce9b76f025d8ee0ac1e61bb3c302 to your computer and use it in GitHub Desktop.
Save rojan-rijal/6919ce9b76f025d8ee0ac1e61bb3c302 to your computer and use it in GitHub Desktop.
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()
alert test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment