From 1ae86e28984462a92e327819bd7c9b0812f1a087 Mon Sep 17 00:00:00 2001 From: needlen0se <116135691+needlen0se@users.noreply.github.com> Date: Wed, 19 Oct 2022 15:18:22 -0700 Subject: [PATCH 1/2] Error if XML is missing --- Util/MachineProductCfg.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Util/MachineProductCfg.py b/Util/MachineProductCfg.py index 77722c7..221e8fe 100644 --- a/Util/MachineProductCfg.py +++ b/Util/MachineProductCfg.py @@ -1,13 +1,18 @@ import json +import sys import xmltodict # Open the MachineProductCfg.xml file in the root directory -with open("MachineProductCfg.xml", mode = 'r', encoding= 'utf-8') as MPCxml: - MPCdict = xmltodict.parse(MPCxml.read()) - MPCdump = json.dumps(MPCdict) - data = json.loads(MPCdump) - +try: + with open("MachineProductCfg.xml", mode = 'r', encoding= 'utf-8') as MPCxml: + MPCdict = xmltodict.parse(MPCxml.read()) + MPCdump = json.dumps(MPCdict) + data = json.loads(MPCdump) +except Exception as e: + print(e) + sys.exit("There was an error opening your MachineProductCfg.xml. Is the file in the root folder?") + def getPrimaryLocations(): """ Returns all of the primary locations in the MachineProductCfg """ From 10586a41f2fb63b24d3b00ec3cb90762d0de9cfe Mon Sep 17 00:00:00 2001 From: needlen0se <116135691+needlen0se@users.noreply.github.com> Date: Wed, 19 Oct 2022 15:25:28 -0700 Subject: [PATCH 2/2] Create folders and files if not exist --- main.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/main.py b/main.py index 5bdc256..905b9f6 100644 --- a/main.py +++ b/main.py @@ -1,13 +1,29 @@ import asyncio +from asyncio.log import logger from asyncore import loop import logging,coloredlogs from recordGenerators import DailyForecast,CurrentObservations,HourlyForecast,AirQuality,AirportDelays,PollenForecast,Breathing,Alerts -# from radar import TWCRadarProcessor, RadarProcessor - +from radar import TWCRadarProcessor, RadarProcessor +import os l = logging.getLogger(__name__) coloredlogs.install(logger=l) +# Create dirs and files +if not os.path.exists('./.temp/'): + os.makedirs('./.temp/') + +if not os.path.exists('./.temp/tiles/'): + os.makedirs('./.temp/tiles/') + +if not os.path.exists('./.temp/tiles/output/'): + os.makedirs('./.temp/tiles/output/') + +if not os.path.exists('./.temp/msgId.txt'): + print("Creating initial msgId file") + with open('./.temp/msgId.txt', "w") as f: + f.write("410080515") + """ CurrentConditions: Every 5 minutes @@ -15,7 +31,7 @@ Daily Forecasts, Hourlies, etc: 60 minutes Alerts: 5 minutes """ l.info("Starting i2RecordCollector") -l.info("Developed by mewtek32, Floppaa, and Goldblaze") +l.info("Developed by mewtek32, Floppaa, Goldblaze, and needlenose") async def grabAlertsLoop(): while True: