Ver código fonte

Add try/except block to catch weird error

Foppe Hemminga 6 anos atrás
pai
commit
8265f3e600
1 arquivos alterados com 20 adições e 14 exclusões
  1. 20 14
      main.py

+ 20 - 14
main.py

@@ -61,20 +61,26 @@ if __name__ == '__main__':
                 # print(row)
                 # if type(row) == 'datetime.time':
                 #     continue
-                if (
-                        scratching.date == row.race_date.strftime('%Y-%m-%d') and
-                        scratching.venue == row.venue and
-                        int(scratching.race) == int(row.race) and
-                        scratching.horse == row.horse
-                ):
-                    message_string = 'Horse found: date = {}, venue = {}, race = {}, horse = {}'
-                    message = message_string.format(scratching.date,
-                                                    scratching.venue,
-                                                    scratching.race,
-                                                    scratching.horse)
-                    # print(message)
-                    # print(row)
-                    found_in_database = True
+                try:
+                    if (
+                            scratching.date == row.race_date.strftime('%Y-%m-%d') and
+                            scratching.venue == row.venue and
+                            int(scratching.race) == int(row.race) and
+                            scratching.horse == row.horse
+                    ):
+                        message_string = 'Horse found: date = {}, venue = {}, race = {}, horse = {}'
+                        message = message_string.format(scratching.date,
+                                                        scratching.venue,
+                                                        scratching.race,
+                                                        scratching.horse)
+                        # print(message)
+                        # print(row)
+                        found_in_database = True
+                except AttributeError as ae:
+                    print(ae)
+                    print('row: ', end='')
+                    print(row)
+                    continue
             if not found_in_database:
                 # report new scratching
                 date_object = datetime.datetime.strptime(scratching.date, "%Y-%m-%d").date()