فهرست منبع

Add send_only_flagged setting

Foppe Hemminga 6 سال پیش
والد
کامیت
009a3a7ae4
4فایلهای تغییر یافته به همراه11 افزوده شده و 4 حذف شده
  1. 3 0
      .idea/.gitignore
  2. 2 2
      main.py
  3. 4 1
      model.py
  4. 2 1
      racenet.py

+ 3 - 0
.idea/.gitignore

@@ -0,0 +1,3 @@
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml

+ 2 - 2
main.py

@@ -18,6 +18,7 @@ if __name__ == '__main__':
         except ValueError:
             sys.exit(1)
     broadcast = True
+    send_only_flagged = False  # Note: there is another one in racenet.py
     if len(sys.argv) > 2:
         broadcast = False
     start = time.time()
@@ -81,8 +82,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', start)
-
+    model.send_messages(scratchings_to_be_broadcast, 'RA', start, send_only_flagged)
     db.close()
 
     interim = time.time()

+ 4 - 1
model.py

@@ -107,7 +107,7 @@ def convert_to_date(weird_string):
     return calculated_date
 
 
-def send_messages(scratches, source, start=0):
+def send_messages(scratches, source, start=0, send_only_flagged=False):
     long_message = ''
 
     message_string = '{} {}venue = {} {} {}-{} | race = {} starts at {} | {} UTC | horse = {}{}'
@@ -116,6 +116,9 @@ def send_messages(scratches, source, start=0):
         flag = ''
         if m.torn:
             flag = 'FLAGGED!! '
+        elif send_only_flagged:
+            # Discard messages that are not flagged
+            continue
         pprint(m)
         end = time.time()
         message = message_string.format(source,

+ 2 - 1
racenet.py

@@ -10,6 +10,7 @@ import textwrap
 import database
 import time
 
+send_only_flagged = False
 # Data = collections.namedtuple('Data', 'venue state race time horse_no horse flag')
 start = time.time()
 
@@ -77,4 +78,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', start)
+    model.send_messages(scratchings_to_be_broadcast, 'RN', start, send_only_flagged)