-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·69 lines (49 loc) · 1.8 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
#!/usr/bin/env python3
import json
import time
import requests
import bot
from bs4 import BeautifulSoup
def get_page():
return requests.get("https://athene.fi/jobs/")
def soup():
return BeautifulSoup(get_page().content, 'html.parser')
def get_listings():
listings = []
job_listings = soup().find('ul', {'class': 'job_listings'})
if job_listings == None:
print("Error while fetching webpage...")
return []
for job_listing in job_listings.find_all('li', {'class': 'job_listing'}):
listing_data = {
'job_title': job_listing.find('h3').text,
'company': job_listing.find('div', {'class': 'company'}).strong.text,
'link_to_job': job_listing.find('a')['href']
}
listings.append(listing_data)
return listings
def update_data():
with open('data.json', "w") as outfile:
data = {}
data['active_jobs'] = get_listings()
json.dump(data, outfile, indent=2)
# Updates data.json when bot is started, so it doesn't spam if if has been off for a while
update_data()
print("Bot is running...")
while True:
data_file = open('data.json')
old_listings = json.load(data_file)['active_jobs']
new_listings = get_listings()
data_file.close()
if (old_listings != new_listings):
new_jobs = [item for item in new_listings if item not in old_listings]
for job in new_jobs:
job_title = job['job_title']
company = job['company']
link_to_job = job['link_to_job']
message = f"Hello there, *{company}* is searching for *{job_title}*. Read more from here... \n\n{link_to_job}"
bot.send_message(message)
print(message)
# After sending messages, update data.json
update_data()
time.sleep(10)