diff --git a/recordGenerators/Breathing.py b/recordGenerators/Breathing.py
index 6d93690..37e79b9 100644
--- a/recordGenerators/Breathing.py
+++ b/recordGenerators/Breathing.py
@@ -6,6 +6,7 @@ import os
import shutil
import xml.dom.minidom
import logging,coloredlogs
+import aiohttp, aiofiles
sys.path.append("./py2lib")
sys.path.append("./Util")
@@ -30,14 +31,14 @@ l.debug(coopIds, geocodes)
apiKey = '21d8a80b3d6b444998a80b3d6b1449d3'
-def getData(coopId, geocode):
+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}"
+ data = ""
#Fetch data
-
- response = requests.get(fetchUrl)
-
- data = response.text
+ async with aiohttp.ClientSession() as s:
+ async with s.get(fetchUrl) as r:
+ data = await r.text()
newData = data[63:-26]
@@ -45,32 +46,32 @@ def getData(coopId, geocode):
#Write to .i2m file
i2Doc = '' + '' + newData + '' + str(coopId) + ''
- f = open("./.temp/Breathing.i2m", "a")
- f.write(i2Doc)
- f.close()
+ async with aiofiles.open("./.temp/Breathing.i2m", "a") as f:
+ await f.write(i2Doc)
+ await f.close()
-def makeDataFile():
+async def makeDataFile():
l.info("Writing a Breathing forecast record.")
header = ''
footer = ''
- with open("./.temp/Breathing.i2m", 'w') as doc:
- doc.write(header)
+ async with aiofiles.open("./.temp/Breathing.i2m", 'w') as doc:
+ await doc.write(header)
for x, y in zip(coopIds, geocodes):
- getData(x, y)
+ await getData(x, y)
- with open("./.temp/Breathing.i2m", 'a') as end:
- end.write(footer)
+ async with aiofiles.open("./.temp/Breathing.i2m", 'a') as end:
+ await end.write(footer)
dom = xml.dom.minidom.parse("./.temp/Breathing.i2m")
pretty_xml_as_string = dom.toprettyxml(indent = " ")
- with open("./.temp/Breathing.i2m", "w") as g:
- g.write(pretty_xml_as_string[23:])
- g.close()
+ async with aiofiles.open("./.temp/Breathing.i2m", "w") as g:
+ await g.write(pretty_xml_as_string[23:])
+ await g.close()
files = []
commands = []