|
|
@@ -35,9 +35,6 @@ if __name__ == '__main__':
|
|
|
race_day_details = model.process_raw_data(raw_data, race_day)
|
|
|
race_days.append(race_day_details)
|
|
|
raw_data_dict[race_day.name] = raw_data
|
|
|
- interim = time.time()
|
|
|
- # print('interim 2 {}'.format(interim - start))
|
|
|
- # pprint(race_days)
|
|
|
|
|
|
races = model.get_relevant_races_from_database(db)
|
|
|
|
|
|
@@ -80,90 +77,6 @@ if __name__ == '__main__':
|
|
|
full_scratchings.append(full_scratching)
|
|
|
continue
|
|
|
|
|
|
- """
|
|
|
- # ### OLD ###
|
|
|
- found_in_database = False
|
|
|
- # if db_data is None:
|
|
|
- # print(' 62. Caught db_data is None')
|
|
|
- # found_in_database = False
|
|
|
- # else:
|
|
|
- for row in db_data_query1:
|
|
|
- # print('row: ', end = '')
|
|
|
- # print(type(row))
|
|
|
- # print(row)
|
|
|
- # if type(row) == 'datetime.time':
|
|
|
- # continue
|
|
|
- try:
|
|
|
- # if not hasattr(db_data, 'name'):
|
|
|
- # continue
|
|
|
- date_in_db_row_formatted = row.race_date.strftime('%Y-%m-%d')
|
|
|
-
|
|
|
- if (
|
|
|
- scratching.date == date_in_db_row_formatted and
|
|
|
- scratching.venue == row.venue and
|
|
|
- int(scratching.race) == int(row.race) and
|
|
|
- scratching.horse_no == row.horse_no
|
|
|
- ):
|
|
|
- message_string = 'Horse found: date = {}, venue = {}, race = {}, horse = {}'
|
|
|
- message = message_string.format(scratching.date,
|
|
|
- scratching.venue,
|
|
|
- scratching.race,
|
|
|
- '{} {}'.format(
|
|
|
- scratching.horse_no, scratching.horse_display_name))
|
|
|
- # print(message)
|
|
|
- # print(row)
|
|
|
- found_in_database = True
|
|
|
- except AttributeError as ae:
|
|
|
- print(ae)
|
|
|
- print(' 94. row: ', end='')
|
|
|
- print(row)
|
|
|
- pprint(db_data_query1)
|
|
|
- continue
|
|
|
- if not found_in_database:
|
|
|
- # report new scratching
|
|
|
- date_object = datetime.datetime.strptime(scratching.date, "%Y-%m-%d").date()
|
|
|
- day_abbr = date_object.strftime('%a')
|
|
|
- query = """
|
|
|
- # SELECT start_time, utctime, torn FROM race_program
|
|
|
- # WHERE race_date = %s AND
|
|
|
- # venue = %s AND
|
|
|
- # race = %s;
|
|
|
- """
|
|
|
- cur2 = db.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
|
|
|
- cur2.execute(query, (scratching.date, scratching.venue, scratching.race))
|
|
|
- db_data_query2 = cur2.fetchone()
|
|
|
- cur2.close()
|
|
|
- if db_data_query2 is None or len(db_data_query2) == 0:
|
|
|
- print('106. cursor.execute(query, (scratching.date, scratching.venue, scratching.race))')
|
|
|
- print('107. cursor.execute({}, ({}, {}, {}))'.format(
|
|
|
- query, scratching.date, scratching.venue, scratching.race
|
|
|
- ))
|
|
|
- print('110. No race found')
|
|
|
- continue
|
|
|
- flag = ''
|
|
|
- if db_data_query2.torn:
|
|
|
- flag = 'FLAGGED!! '
|
|
|
- message_string = '{}venue = {} {} {}-{} | race = {} starts at {} | {} UTC | horse = {}'
|
|
|
- message = message_string.format(flag,
|
|
|
- day_abbr,
|
|
|
- scratching.date,
|
|
|
- scratching.state,
|
|
|
- scratching.venue,
|
|
|
- scratching.race,
|
|
|
- db_data_query2.start_time.strftime('%H:%M'),
|
|
|
- db_data_query2.utctime.strftime('%H:%M'),
|
|
|
- '{} {}'.format(scratching.horse_no, scratching.horse_display_name))
|
|
|
- print(message)
|
|
|
- if broadcast or flag == 'FLAGGED!! ':
|
|
|
- messages.append(message)
|
|
|
- # view.broadcast(message)
|
|
|
- # store new scratching
|
|
|
- scratchings_for_database.append((scratching.venue, scratching.date,
|
|
|
- scratching.race, scratching.horse_no, scratching.horse_display_name))
|
|
|
- """
|
|
|
- # pprint(full_scratchings)
|
|
|
- # print('len(full_scratchings): {}'.format(len(full_scratchings)))
|
|
|
-
|
|
|
if (arrow.utcnow().minute + 4) % 20 == 0:
|
|
|
pprint(full_scratchings)
|
|
|
scratchings_to_be_broadcast = model.store_scratched_horses(db, full_scratchings)
|