|
|
@@ -2,14 +2,24 @@ import json
|
|
|
# from pprint import pprint
|
|
|
from model import local_timezones
|
|
|
import arrow
|
|
|
-import collections
|
|
|
+# import collections
|
|
|
+import _bs
|
|
|
+import model
|
|
|
+# import re
|
|
|
+import textwrap
|
|
|
+import database
|
|
|
|
|
|
-Data = collections.namedtuple('Data', 'venue state race time horse_no horse flag')
|
|
|
+# Data = collections.namedtuple('Data', 'venue state race time horse_no horse flag')
|
|
|
|
|
|
-with open('scratchings.json', 'r') as f:
|
|
|
- data_all = json.loads(f.read())
|
|
|
- data = data_all["MainPageState"]["receivedData"][0]
|
|
|
- name = data['name']
|
|
|
+my_json = model.scrape_racenet_main_page()
|
|
|
+my_json = textwrap.fill(my_json[:-1], 1e6)
|
|
|
+# print(my_json)
|
|
|
+# exit(0)
|
|
|
+# with open('scratchings.json', 'r') as f:
|
|
|
+data_all = json.loads(my_json)
|
|
|
+# pprint(data_all)
|
|
|
+data = data_all["MainPageState"]["receivedData"][0]
|
|
|
+name = data['name']
|
|
|
|
|
|
print(name)
|
|
|
items = 0
|
|
|
@@ -25,6 +35,7 @@ for d in data['data']:
|
|
|
timezone)
|
|
|
print(venue)
|
|
|
races = d['races']
|
|
|
+ scratchings = []
|
|
|
for race in races:
|
|
|
raceNumber = race['raceNumber']
|
|
|
startTimeLocal = race['startTimeLocal'][11:-3]
|
|
|
@@ -40,7 +51,16 @@ for d in data['data']:
|
|
|
horseDisplayName = runner['horseDisplayName']
|
|
|
horseNumber = runner['horseNumber']
|
|
|
# print('\t{:2d}: {}'.format(horseNumber, horseDisplayName))
|
|
|
- data_without_flag = Data(d['venue']['name'], d['venue']['state'] if is_aus else 'NZL',
|
|
|
- raceNumber, arrowStartTimeLocal,
|
|
|
- horseNumber, horseDisplayName, False)
|
|
|
- print(data_without_flag)
|
|
|
+ # data_without_flag = Data(d['venue']['name'], d['venue']['state'] if is_aus else 'NZL',
|
|
|
+ # raceNumber, arrowStartTimeLocal,
|
|
|
+ # horseNumber, horseDisplayName, False)
|
|
|
+ data_without_flag = _bs.Scratching(d['venue']['name'], d['venue']['state'] if is_aus else 'NZL',
|
|
|
+ arrowStartTimeLocal.date(), raceNumber,
|
|
|
+ arrowStartTimeLocal.format('HH:mm'),
|
|
|
+ arrowStartTimeLocal.to('utc').format('HH:mm'), horseNumber,
|
|
|
+ horseDisplayName, False)
|
|
|
+ scratchings.append(data_without_flag)
|
|
|
+ db = database.db
|
|
|
+ scratchings_to_be_broadcast = model.store_scratched_horses(db, scratchings)
|
|
|
+ # print('len(scratchings_to_be_broadcast): {}'.format(len(scratchings_to_be_broadcast)))
|
|
|
+ model.send_messages(scratchings_to_be_broadcast, 'RN')
|