mirror of
				https://github.com/mewtek/i2ME-Legacy.git
				synced 2025-06-10 05:30:00 -05:00 
			
		
		
		
	Bugfix for broken TWC alerts
This commit is contained in:
		| @@ -1,3 +1,4 @@ | |||||||
|  | from weakref import KeyedRef | ||||||
| import requests | import requests | ||||||
| import json | import json | ||||||
| import os | import os | ||||||
| @@ -33,9 +34,6 @@ def getAlerts(location): | |||||||
|  |  | ||||||
|     theCode = response.status_code |     theCode = response.status_code | ||||||
|  |  | ||||||
|     #Our global variables |  | ||||||
|      |  | ||||||
|      |  | ||||||
|     #Set the actions based on response code |     #Set the actions based on response code | ||||||
|     if theCode == 204: |     if theCode == 204: | ||||||
|         print('No alerts for area ' + location + '.\n') |         print('No alerts for area ' + location + '.\n') | ||||||
| @@ -67,6 +65,7 @@ def getAlerts(location): | |||||||
|     elif theCode == 200: |     elif theCode == 200: | ||||||
|         pass |         pass | ||||||
|      |      | ||||||
|  |     try: | ||||||
|         #Alright lets map our headline variables. |         #Alright lets map our headline variables. | ||||||
|         l.debug('Found Alert for ' + location + '\n') |         l.debug('Found Alert for ' + location + '\n') | ||||||
|         dataH = response.json() |         dataH = response.json() | ||||||
| @@ -315,6 +314,11 @@ def getAlerts(location): | |||||||
|             with open('./.temp/alertmanifest.txt', "a") as c: |             with open('./.temp/alertmanifest.txt', "a") as c: | ||||||
|                 c.write('\n' + location + '_' + x['phenomena'] + '_' + x['significance'] + '_' + str(x['processTimeUTC'])) |                 c.write('\n' + location + '_' + x['phenomena'] + '_' + x['significance'] + '_' + str(x['processTimeUTC'])) | ||||||
|                 c.close() |                 c.close() | ||||||
|  |     except KeyError: | ||||||
|  |         # For some reason, TWC will return a 200 even though there's no alerts present in the API. | ||||||
|  |         l.error("DO NOT REPORT THE ERROR BELOW") | ||||||
|  |         l.error("Failed to write BERecord - Returned 200 but had no alerts.") | ||||||
|  |         os.remove('./.temp/BERecord.xml') | ||||||
|  |  | ||||||
|  |  | ||||||
| # TODO: This should be converted into a function so it works better with async, that way we're not getting hung up on that time.sleep() call. | # TODO: This should be converted into a function so it works better with async, that way we're not getting hung up on that time.sleep() call. | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user