Open CurrentObservations.i2m file asynchronously

This commit is contained in:
April 2022-11-12 12:45:01 -07:00
parent 60241d7c18
commit bdbd707b32
No known key found for this signature in database
GPG Key ID: 17A9A017FAA4DE5E

View File

@ -59,25 +59,26 @@ async def makeDataFile():
header = '<Data type="CurrentObservations">' header = '<Data type="CurrentObservations">'
footer = '</Data>' footer = '</Data>'
with open("./.temp/CurrentObservations.i2m", 'w') as doc: async with aiofiles.open("./.temp/CurrentObservations.i2m", 'w') as doc:
doc.write(header) await doc.write(header)
for x, y in zip(tecciId, zipCodes): for x, y in zip(tecciId, zipCodes):
getData(x, y) getData(x, y)
with open("./.temp/CurrentObservations.i2m", 'a') as end: async with aiofiles.open("./.temp/CurrentObservations.i2m", 'a') as end:
end.write(footer) await end.write(footer)
dom = xml.dom.minidom.parse("./.temp/CurrentObservations.i2m") dom = xml.dom.minidom.parse("./.temp/CurrentObservations.i2m")
pretty_xml_as_string = dom.toprettyxml(indent = " ") pretty_xml_as_string = dom.toprettyxml(indent = " ")
with open("./.temp/CurrentObservations.i2m", "w") as g: async with aiofiles.open("./.temp/CurrentObservations.i2m", "w") as g:
g.write(pretty_xml_as_string[23:]) await g.write(pretty_xml_as_string[23:])
g.close() await g.close()
files = [] files = []
commands = [] 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 open("./.temp/CurrentObservations.i2m", 'rb') as f_in:
with gzip.open("./.temp/CurrentObservations.gz", 'wb') as f_out: with gzip.open("./.temp/CurrentObservations.gz", 'wb') as f_out:
shutil.copyfileobj(f_in, f_out) shutil.copyfileobj(f_in, f_out)