From 4afc4b3ad02ae0c01192638a05db5f1199a409b0 Mon Sep 17 00:00:00 2001 From: iRaven4522 Date: Tue, 28 Jan 2025 17:41:50 -0600 Subject: [PATCH] cfg json bullcrap --- .gitignore | 4 +++- main.py | 2 +- py2Lib/bit.py | 4 ++-- radar/TWCRadarCollector.py | 8 ++++---- radar/TWCRadarProcessor.py | 2 +- radar/TWCSatRadProcessor.py | 2 +- recordGenerators/AchesAndPains.py | 2 +- recordGenerators/AirQuality.py | 2 +- recordGenerators/AirportDelays.py | 2 +- recordGenerators/Alerts.py | 4 ++-- recordGenerators/Breathing.py | 2 +- recordGenerators/CurrentObservations.py | 2 +- recordGenerators/DailyForecast.py | 2 +- recordGenerators/HeatingAndCooling.py | 2 +- recordGenerators/HourlyForecast.py | 2 +- recordGenerators/MosquitoActivity.py | 2 +- recordGenerators/PollenForecast.py | 2 +- recordGenerators/TideForecast.py | 2 +- recordGenerators/WateringNeeds.py | 2 +- 19 files changed, 26 insertions(+), 24 deletions(-) diff --git a/.gitignore b/.gitignore index d26e866..6e9dc46 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,6 @@ tiles/* __pycache__/ # Temp directory -.temp/ \ No newline at end of file +.temp/ + +conf.json \ No newline at end of file diff --git a/main.py b/main.py index 88eae6d..5278a1c 100644 --- a/main.py +++ b/main.py @@ -15,7 +15,7 @@ with open("conf.json", "r") as file: l = logging.getLogger(__name__) coloredlogs.install(logger=l) -useRadarServer = cfg[useRadarServer] +useRadarServer = cfg["useRadarServer"] async def createTemp(): """ Used on a first time run, creates necessary files & directories for the message encoder to work properly. """ diff --git a/py2Lib/bit.py b/py2Lib/bit.py index 988fdd6..158be51 100644 --- a/py2Lib/bit.py +++ b/py2Lib/bit.py @@ -15,8 +15,8 @@ with open("conf.json", "r") as file: l = logging.getLogger(__name__) coloredlogs.install() -MCAST_GRP = cfg[multicastGroup] -MCAST_IF = cfg[multicastIf] +MCAST_GRP = cfg["multicastGroup"] +MCAST_IF = cfg["multicastIf"] BUF_SIZE = 1396 MULTICAST_TTL = 2 diff --git a/radar/TWCRadarCollector.py b/radar/TWCRadarCollector.py index d766625..b9b23fc 100644 --- a/radar/TWCRadarCollector.py +++ b/radar/TWCRadarCollector.py @@ -24,12 +24,12 @@ async def getValidTimestamps(radarType:str) -> list: async with aiohttp.ClientSession() as s: if (radarType == "satrad"): maxImages = 12 - url = "https://api.weather.com/v3/TileServer/series/productSet?apiKey=" + cfg[twcApiKey] + "&filter=satrad" + url = "https://api.weather.com/v3/TileServer/series/productSet?apiKey=" + cfg["twcApiKey"] + "&filter=satrad" series = 'satrad' elif (radarType == "radarmosaic"): maxImages = 36 - url = "https://api.weather.com/v3/TileServer/series/productSet?apiKey=" + cfg[twcApiKey] + "&filter=twcRadarMosaic" + url = "https://api.weather.com/v3/TileServer/series/productSet?apiKey=" + cfg["twcApiKey"] + "&filter=twcRadarMosaic" series = 'twcRadarMosaic' else: @@ -52,9 +52,9 @@ async def downloadRadarFrames(radarType:str, timestamps: list) -> list: imagesToSend = [] if (radarType == "satrad"): - url_root = cfg[radarBaseUrl] + url_root = cfg["radarBaseUrl"] elif (radarType == "radarmosaic"): - url_root = cfg[radarBaseUrl] + url_root = cfg["radarBaseUrl"] else: l.error(f'Invalid radar type "{radarType}" -- Valid radar types include "satrad", "radarmosaic"') return diff --git a/radar/TWCRadarProcessor.py b/radar/TWCRadarProcessor.py index 152dc1b..b8ec4c2 100644 --- a/radar/TWCRadarProcessor.py +++ b/radar/TWCRadarProcessor.py @@ -38,7 +38,7 @@ async def getValidTimestamps(boundaries:ImageBoundaries) -> list: times = [] async with aiohttp.ClientSession() as session: - url = "https://api.weather.com/v3/TileServer/series/productSet?apiKey=" + cfg[twcApiKey] + "&filter=twcRadarMosaic" + url = "https://api.weather.com/v3/TileServer/series/productSet?apiKey=" + cfg["twcApiKey"] + "&filter=twcRadarMosaic" async with session.get(url) as r: response = await r.json() diff --git a/radar/TWCSatRadProcessor.py b/radar/TWCSatRadProcessor.py index 7e6362f..4f9fd44 100644 --- a/radar/TWCSatRadProcessor.py +++ b/radar/TWCSatRadProcessor.py @@ -19,7 +19,7 @@ async def getValidTimestamps(boundaries:ImageBoundaries) -> list: times = [] async with aiohttp.ClientSession() as session: - url = "https://api.weather.com/v3/TileServer/series/productSet?apiKey=" + cfg[twcApiKey] + "&filter=twcRadarMosaic" + url = "https://api.weather.com/v3/TileServer/series/productSet?apiKey=" + cfg["twcApiKey"] + "&filter=twcRadarMosaic" async with session.get(url) as r: response = await r.json() diff --git a/recordGenerators/AchesAndPains.py b/recordGenerators/AchesAndPains.py index 0aa9a51..5183a80 100644 --- a/recordGenerators/AchesAndPains.py +++ b/recordGenerators/AchesAndPains.py @@ -24,7 +24,7 @@ import json with open("conf.json", "r") as file: cfg = json.load(file) -apiKey = cfg[twcApiKey] +apiKey = cfg["twcApiKey"] async def getData(coopId, geocode): fetchUrl = f"https://api.weather.com/v2/indices/achePain/daypart/7day?geocode={geocode}&language=en-US&format=xml&apiKey={apiKey}" diff --git a/recordGenerators/AirQuality.py b/recordGenerators/AirQuality.py index 1583671..b78ea9b 100644 --- a/recordGenerators/AirQuality.py +++ b/recordGenerators/AirQuality.py @@ -31,7 +31,7 @@ import json with open("conf.json", "r") as file: cfg = json.load(file) -apiKey = cfg[twcApiKey] +apiKey = cfg["twcApiKey"] async def getData(epaId, zipcode): url = f"https://api.weather.com/v1/location/{zipcode}:4:US/airquality.xml?language=en-US&apiKey={apiKey}" diff --git a/recordGenerators/AirportDelays.py b/recordGenerators/AirportDelays.py index b8f952c..83f00f8 100644 --- a/recordGenerators/AirportDelays.py +++ b/recordGenerators/AirportDelays.py @@ -33,7 +33,7 @@ import json with open("conf.json", "r") as file: cfg = json.load(file) -apiKey = cfg[twcApiKey] +apiKey = cfg["twcApiKey"] async def getData(airport): url = f"https://api.weather.com/v1/airportcode/{airport}/airport/delays.xml?language=en-US&apiKey={apiKey}" diff --git a/recordGenerators/Alerts.py b/recordGenerators/Alerts.py index f7cfec3..d761e4d 100644 --- a/recordGenerators/Alerts.py +++ b/recordGenerators/Alerts.py @@ -26,8 +26,8 @@ import json with open("conf.json", "r") as file: cfg = json.load(file) -headlineApiKey = cfg[twcApiKey] -detailsApiKey = cfg[twcApiKey] +headlineApiKey = cfg["twcApiKey"] +detailsApiKey = cfg["twcApiKey"] k = 0 async def getAlerts(location): diff --git a/recordGenerators/Breathing.py b/recordGenerators/Breathing.py index 96431b2..d716bc0 100644 --- a/recordGenerators/Breathing.py +++ b/recordGenerators/Breathing.py @@ -34,7 +34,7 @@ import json with open("conf.json", "r") as file: cfg = json.load(file) -apiKey = cfg[twcApiKey] +apiKey = cfg["twcApiKey"] async def getData(coopId, geocode): fetchUrl = f"https://api.weather.com/v2/indices/breathing/daypart/7day?geocode={geocode}&language=en-US&format=xml&apiKey={apiKey}" diff --git a/recordGenerators/CurrentObservations.py b/recordGenerators/CurrentObservations.py index 21cc015..c4a4396 100644 --- a/recordGenerators/CurrentObservations.py +++ b/recordGenerators/CurrentObservations.py @@ -38,7 +38,7 @@ import json with open("conf.json", "r") as file: cfg = json.load(file) -apiKey = cfg[twcApiKey] +apiKey = cfg["twcApiKey"] async def getData(tecci, zipCode): l.debug('Gathering data for location id ' + tecci) diff --git a/recordGenerators/DailyForecast.py b/recordGenerators/DailyForecast.py index 45e659d..ba8ec02 100644 --- a/recordGenerators/DailyForecast.py +++ b/recordGenerators/DailyForecast.py @@ -36,7 +36,7 @@ import json with open("conf.json", "r") as file: cfg = json.load(file) -apiKey = cfg[twcApiKey] +apiKey = cfg["twcApiKey"] async def getData(tecci, zipCode): fetchUrl = 'https://api.weather.com/v1/location/' + zipCode + ':4:US/forecast/daily/7day.xml?language=en-US&units=e&apiKey=' + apiKey diff --git a/recordGenerators/HeatingAndCooling.py b/recordGenerators/HeatingAndCooling.py index 98176f4..1bebbeb 100644 --- a/recordGenerators/HeatingAndCooling.py +++ b/recordGenerators/HeatingAndCooling.py @@ -24,7 +24,7 @@ import json with open("conf.json", "r") as file: cfg = json.load(file) -apiKey = cfg[twcApiKey] +apiKey = cfg["twcApiKey"] async def getData(coopId, geocode): fetchUrl = f"https://api.weather.com/v2/indices/heatCool/daypart/7day?geocode={geocode}&language=en-US&format=xml&apiKey={apiKey}" diff --git a/recordGenerators/HourlyForecast.py b/recordGenerators/HourlyForecast.py index b8258d8..0c85924 100644 --- a/recordGenerators/HourlyForecast.py +++ b/recordGenerators/HourlyForecast.py @@ -36,7 +36,7 @@ import json with open("conf.json", "r") as file: cfg = json.load(file) -apiKey = cfg[twcApiKey] +apiKey = cfg["twcApiKey"] async def getData(tecci, zipCode): l.debug('Gathering data for location id ' + tecci) diff --git a/recordGenerators/MosquitoActivity.py b/recordGenerators/MosquitoActivity.py index 87dafa7..796903b 100644 --- a/recordGenerators/MosquitoActivity.py +++ b/recordGenerators/MosquitoActivity.py @@ -24,7 +24,7 @@ import json with open("conf.json", "r") as file: cfg = json.load(file) -apiKey = cfg[twcApiKey] +apiKey = cfg["twcApiKey"] async def getData(coopId, geocode): fetchUrl = f"https://api.weather.com/v2/indices/mosquito/daily/7day?geocode={geocode}&language=en-US&format=xml&apiKey={apiKey}" diff --git a/recordGenerators/PollenForecast.py b/recordGenerators/PollenForecast.py index e04b535..89a624f 100644 --- a/recordGenerators/PollenForecast.py +++ b/recordGenerators/PollenForecast.py @@ -35,7 +35,7 @@ import json with open("conf.json", "r") as file: cfg = json.load(file) -apiKey = cfg[twcApiKey] +apiKey = cfg["twcApiKey"] async def getData(pollenId, geocode): fetchUrl = f"https://api.weather.com/v2/indices/pollen/daypart/7day?geocode={geocode}&language=en-US&format=xml&apiKey={apiKey}" diff --git a/recordGenerators/TideForecast.py b/recordGenerators/TideForecast.py index 3a37928..771330f 100644 --- a/recordGenerators/TideForecast.py +++ b/recordGenerators/TideForecast.py @@ -24,7 +24,7 @@ import json with open("conf.json", "r") as file: cfg = json.load(file) -apiKey = cfg[twcApiKey] +apiKey = cfg["twcApiKey"] async def getData(tideStation, geocode): today = datetime.date.today() diff --git a/recordGenerators/WateringNeeds.py b/recordGenerators/WateringNeeds.py index 198c28d..c37190f 100644 --- a/recordGenerators/WateringNeeds.py +++ b/recordGenerators/WateringNeeds.py @@ -24,7 +24,7 @@ import json with open("conf.json", "r") as file: cfg = json.load(file) -apiKey = cfg[twcApiKey] +apiKey = cfg["twcApiKey"] async def getData(coopId, geocode): fetchUrl = f"https://api.weather.com/v2/indices/wateringNeeds/daypart/7day?geocode={geocode}&language=en-US&format=xml&apiKey={apiKey}"