From bdbd707b32346e51b1b1b2d2a71ffed91832ef27 Mon Sep 17 00:00:00 2001 From: April Date: Sat, 12 Nov 2022 12:45:01 -0700 Subject: [PATCH] Open CurrentObservations.i2m file asynchronously --- recordGenerators/CurrentObservations.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/recordGenerators/CurrentObservations.py b/recordGenerators/CurrentObservations.py index 1775d88..43bfe57 100644 --- a/recordGenerators/CurrentObservations.py +++ b/recordGenerators/CurrentObservations.py @@ -59,25 +59,26 @@ async def makeDataFile(): header = '' footer = '' - with open("./.temp/CurrentObservations.i2m", 'w') as doc: - doc.write(header) + async with aiofiles.open("./.temp/CurrentObservations.i2m", 'w') as doc: + await doc.write(header) for x, y in zip(tecciId, zipCodes): getData(x, y) - with open("./.temp/CurrentObservations.i2m", 'a') as end: - end.write(footer) + async with aiofiles.open("./.temp/CurrentObservations.i2m", 'a') as end: + await end.write(footer) dom = xml.dom.minidom.parse("./.temp/CurrentObservations.i2m") pretty_xml_as_string = dom.toprettyxml(indent = " ") - with open("./.temp/CurrentObservations.i2m", "w") as g: - g.write(pretty_xml_as_string[23:]) - g.close() + async with aiofiles.open("./.temp/CurrentObservations.i2m", "w") as g: + await g.write(pretty_xml_as_string[23:]) + await g.close() files = [] commands = [] + # This causes blocking but there's not really much we can do about it :( with open("./.temp/CurrentObservations.i2m", 'rb') as f_in: with gzip.open("./.temp/CurrentObservations.gz", 'wb') as f_out: shutil.copyfileobj(f_in, f_out)