-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
36 lines (33 loc) · 1.47 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
import time
import database
import scraper as sc
import config
import notifications
import logging
logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
config = config.Config()
scraper = sc.Scraper()
database = database.Database()
pushover = notifications.Pushover(config.get_pushover_token(), config.get_pushover_user())
logging.info("Application started successfully.")
while True:
for query in config.get_queries():
results = scraper.search(query.build_url())
if results: # Make sure there are results to iterate through.
for ad in results:
ad = scraper.parse_ad(ad)
exists = database.exists(ad)
if not exists:
# This is an ad we've never seen before.
database.save_ad(ad)
if query.send_notifications():
if (ad.is_business and query.include_business()) or (not ad.is_business):
pushover.send_notification(ad)
else:
# We've seen this ad before, let's look for any changes.
changes = database.compare(ad, True)
if len(changes) > 0:
if query.send_notifications():
if (ad.is_business and query.include_business()) or (not ad.is_business):
pushover.send_notification(ad, changes)
time.sleep(config.get_scan_interval())