소스 검색

Merge branch 'master' of https://git.fop.pe/Foppe/scratchings

Afwas [1337627 6 년 전
부모
커밋
8ab9057629
2개의 변경된 파일9개의 추가작업 그리고 7개의 파일을 삭제
  1. 7 6
      main.py
  2. 2 1
      view.py

+ 7 - 6
main.py

@@ -4,6 +4,8 @@ from pprint import pprint
 import time
 import database
 import sys
+import view
+
 
 if __name__ == '__main__':
     row = 0
@@ -48,8 +50,8 @@ if __name__ == '__main__':
         db_data = cursor.fetchall()
 
         # compare retrieved scratchings with new data
-        match = False
         for scratching in scratchings:
+            found_in_database = False
             for row in db_data:
                 # print(row)
                 if (
@@ -62,19 +64,18 @@ if __name__ == '__main__':
                                                                                                  scratching.venue,
                                                                                                  scratching.race,
                                                                                                  scratching.horse)
-                    print(message)
-                    match = True
-            if not match:
+                    # print(message)
+                    found_in_database = True
+            if not found_in_database:
                 # report new scratching
                 message = 'New scratching: {} {} race {} horse {}'.format(scratching.date, scratching.venue,
                                                                           scratching.race, scratching.horse)
-                print(message)
+                view.broadcast(message)
                 # store new scratching
                 query = "INSERT INTO horses(venue, race_date, race, horse) VALUES(%s, %s, %s, %s)"
                 cursor.execute(query, (scratching.venue, scratching.date,
                                        scratching.race, scratching.horse))
             db.commit()
-            match = False
     cursor.close()
     db.close()
 

+ 2 - 1
view.py

@@ -1,6 +1,7 @@
 import os
 import datetime
 import requests
+from dotenv import load_dotenv
 
 
 def broadcast(this_message):
@@ -10,7 +11,7 @@ def broadcast(this_message):
     :return:
     """
     # development only
-    # load_dotenv()
+    load_dotenv()
     url = os.environ["BROADCAST_URL"]
     this_time = datetime.datetime.utcnow().strftime('%Y-%m-%d %H:%M')
     json = {'content': this_time+': '+this_message}