|
@@ -59,6 +59,7 @@ if __name__ == '__main__':
|
|
|
|
|
|
|
|
# compare retrieved scratchings with new data
|
|
# compare retrieved scratchings with new data
|
|
|
scratchings_for_database = []
|
|
scratchings_for_database = []
|
|
|
|
|
+ messages = []
|
|
|
for scratching in scratchings:
|
|
for scratching in scratchings:
|
|
|
found_in_database = False
|
|
found_in_database = False
|
|
|
# if db_data is None:
|
|
# if db_data is None:
|
|
@@ -132,13 +133,29 @@ if __name__ == '__main__':
|
|
|
scratching.horse)
|
|
scratching.horse)
|
|
|
print(message)
|
|
print(message)
|
|
|
if broadcast:
|
|
if broadcast:
|
|
|
- view.broadcast(message)
|
|
|
|
|
|
|
+ messages.append(message)
|
|
|
|
|
+ # view.broadcast(message)
|
|
|
# store new scratching
|
|
# store new scratching
|
|
|
scratchings_for_database.append((scratching.venue, scratching.date,
|
|
scratchings_for_database.append((scratching.venue, scratching.date,
|
|
|
scratching.race, scratching.horse))
|
|
scratching.race, scratching.horse))
|
|
|
|
|
+
|
|
|
|
|
+ long_message = ''
|
|
|
|
|
+ for this_message in messages:
|
|
|
|
|
+ # Append message if possible
|
|
|
|
|
+ if len(long_message) + len(this_message) < 5997:
|
|
|
|
|
+ long_message += '\n' + this_message
|
|
|
|
|
+ else:
|
|
|
|
|
+ # Send long message (max 6k characters)
|
|
|
|
|
+ view.broadcast(long_message)
|
|
|
|
|
+ long_message = this_message
|
|
|
|
|
+ # Send only or last message
|
|
|
|
|
+ if len(this_message) > 0:
|
|
|
|
|
+ view.broadcast(this_message)
|
|
|
|
|
+ this_message = ''
|
|
|
|
|
+
|
|
|
query = """INSERT INTO horses(venue, race_date, race, horse)
|
|
query = """INSERT INTO horses(venue, race_date, race, horse)
|
|
|
- VALUES(%s, %s, %s, %s)
|
|
|
|
|
- ON CONFLICT(venue, race_date, race, horse) DO NOTHING;"""
|
|
|
|
|
|
|
+ VALUES(%s, %s, %s, %s)
|
|
|
|
|
+ ON CONFLICT(venue, race_date, race, horse) DO NOTHING;"""
|
|
|
|
|
|
|
|
cur3 = db.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
|
|
cur3 = db.cursor(cursor_factory=psycopg2.extras.NamedTupleCursor)
|
|
|
for database_entry in scratchings_for_database:
|
|
for database_entry in scratchings_for_database:
|