-
Notifications
You must be signed in to change notification settings - Fork 0
/
do_daily.py
33 lines (30 loc) · 972 Bytes
/
do_daily.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
from persist import Session, Nag, Run
from scrape import RPTodayRaces, RPRaceCard
from datetime import datetime
from sqlalchemy.exc import IntegrityError
from logbook import info, warn, error
def scrapeRuns():
runs = []
today = datetime.now()
for meetingURL in RPTodayRaces(today).cardurls:
try:
race_card = RPRaceCard(meetingURL)
for nag in race_card.runners:
runs.append(
Run( nag["name"] , race_card.location, race_card.time)
)
except Exception, e:
warn("url=" + meetingURL + " " + str(e))
return runs
def doWork():
session = Session()
for run in scrapeRuns():
try:
session.merge(run)
session.commit()
except IntegrityError:
error("Duplicate Run: " + str(run))
session.rollback()
if __name__=='__main__':
info("script='do_daily' event='start'")
doWork()