Cleaned up the event loop

This commit is contained in:
April 2022-10-17 22:53:58 -07:00
parent 591f189a52
commit da0f58390c
No known key found for this signature in database
GPG Key ID: 17A9A017FAA4DE5E

33
main.py
View File

@ -1,6 +1,7 @@
import asyncio import asyncio
import logging,coloredlogs import logging,coloredlogs
from recordGenerators import DailyForecast,CurrentObservations,HourlyForecast,AirQuality,AirportDelays,PollenForecast,Breathing from recordGenerators import DailyForecast,CurrentObservations,HourlyForecast,AirQuality,AirportDelays,PollenForecast,Breathing,Alerts
from radar import TWCRadarProcessor
l = logging.getLogger(__name__) l = logging.getLogger(__name__)
@ -15,13 +16,21 @@ Alerts: 5 minutes
l.info("Starting i2RecordCollector") l.info("Starting i2RecordCollector")
l.info("Developed by mewtek32, Floppaa, and Goldblaze") l.info("Developed by mewtek32, Floppaa, and Goldblaze")
async def grabAlertsLoop():
while True:
Alerts.makeRecord()
await asyncio.sleep(60)
async def RadarProcessingLoop():
while True:
TWCRadarProcessor.makeRadarImages()
await asyncio.sleep(30 * 60)
async def FiveMinUpdaters(): async def FiveMinUpdaters():
while True: while True:
CurrentObservations.makeDataFile() CurrentObservations.makeDataFile()
l.debug("Sleeping for 5 minutes...") l.debug("Sleeping for 5 minutes...")
await asyncio.sleep(300) await asyncio.sleep(5 * 60)
async def HourUpdaters(): async def HourUpdaters():
while True: while True:
@ -32,14 +41,14 @@ async def HourUpdaters():
AirportDelays.writeData() AirportDelays.writeData()
Breathing.makeDataFile() Breathing.makeDataFile()
l.debug("Sleeping for an hour...") l.debug("Sleeping for an hour...")
await asyncio.sleep(3600) await asyncio.sleep(60 * 60)
loop = asyncio.get_event_loop() async def main():
# Create loops
asyncio.create_task(grabAlertsLoop())
asyncio.create_task(FiveMinUpdaters())
asyncio.create_task(HourUpdaters)
asyncio.create_task(RadarProcessingLoop())
hourtasks = loop.create_task(HourUpdaters()) if __name__ == "__main__":
fivemintasks = loop.create_task(FiveMinUpdaters()) asyncio.run(main())
try:
loop.run_until_complete(hourtasks)
loop.run_until_complete(fivemintasks)
except asyncio.CancelledError: pass