ソースを参照

Add timing information to broadcast messages

Foppe Hemminga 6 年 前
コミット
c642416b53
3 ファイル変更10 行追加5 行削除
  1. 1 1
      main.py
  2. 6 3
      model.py
  3. 3 1
      racenet.py

+ 1 - 1
main.py

@@ -168,7 +168,7 @@ if __name__ == '__main__':
         pprint(full_scratchings)
     scratchings_to_be_broadcast = model.store_scratched_horses(db, full_scratchings)
     # print('len(scratchings_to_be_broadcast): {}'.format(len(scratchings_to_be_broadcast)))
-    model.send_messages(scratchings_to_be_broadcast, 'RA')
+    model.send_messages(scratchings_to_be_broadcast, 'RA', start)
 
     db.close()
 

+ 6 - 3
model.py

@@ -9,6 +9,7 @@ import psycopg2.extras
 from pprint import pprint
 import arrow
 import view
+import time
 
 
 import warnings
@@ -106,16 +107,17 @@ def convert_to_date(weird_string):
     return calculated_date
 
 
-def send_messages(scratches, source):
+def send_messages(scratches, source, start=0):
     long_message = ''
 
-    message_string = '{} {}venue = {} {} {}-{} | race = {} starts at {} | {} UTC | horse = {}'
+    message_string = '{} {}venue = {} {} {}-{} | race = {} starts at {} | {} UTC | horse = {}{}'
 
     for m in scratches:
         flag = ''
         if m.torn:
             flag = 'FLAGGED!! '
         pprint(m)
+        end = time.time()
         message = message_string.format(source,
                                         flag,
                                         m.date.strftime('%a'),
@@ -125,7 +127,8 @@ def send_messages(scratches, source):
                                         m.race,
                                         m.time,
                                         m.utc,
-                                        '{} {}'.format(m.horse_no, m.horse_display_name))
+                                        '{} {}'.format(m.horse_no, m.horse_display_name),
+                                        ' | {0:.2f}s'.format(start-end) if start != 0 else '')
         print('this_message: {}'.format(message))
         # Append message if possible
         if len(long_message) + len(message) < 5997:

+ 3 - 1
racenet.py

@@ -8,8 +8,10 @@ import model
 # import re
 import textwrap
 import database
+import time
 
 # Data = collections.namedtuple('Data', 'venue state race time horse_no horse flag')
+start = time.time()
 
 my_json = model.scrape_racenet_scratchings_page()
 my_json = textwrap.fill(my_json[:-1], 1e6)
@@ -75,4 +77,4 @@ for d in data['data']:
     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')
+    model.send_messages(scratchings_to_be_broadcast, 'RN', start)