diff --git a/recordGenerators/DailyForecast.py b/recordGenerators/DailyForecast.py
index acd7133..4f131e7 100644
--- a/recordGenerators/DailyForecast.py
+++ b/recordGenerators/DailyForecast.py
@@ -6,6 +6,7 @@ import os
import shutil
import xml.dom.minidom
import logging,coloredlogs
+import aiofiles, aiohttp
sys.path.append("./py2lib")
sys.path.append("./Util")
@@ -32,14 +33,13 @@ for i in MPC.getMetroCities():
apiKey = '21d8a80b3d6b444998a80b3d6b1449d3'
-def getData(tecci, zipCode):
+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
+ 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[61:-24]
@@ -47,32 +47,32 @@ def getData(tecci, zipCode):
#Write to .i2m file
i2Doc = '' + '' + newData + '' + str(tecci) + ''
- f = open("./.temp/DailyForecast.i2m", "a")
- f.write(i2Doc)
- f.close()
+ async with aiofiles.open('./.temp/DailyForecast.i2m', 'a') as f:
+ await f.write(i2Doc)
+ await f.close()
-def makeDataFile():
+async def makeDataFile():
l.info("Writing a DailyForecast record.")
header = ''
footer = ''
- with open("./.temp/DailyForecast.i2m", 'w') as doc:
- doc.write(header)
+ async with aiofiles.open("./.temp/DailyForecast.i2m", 'w') as doc:
+ await doc.write(header)
for x, y in zip(tecciId, zipCodes):
getData(x, y)
- with open("./.temp/DailyForecast.i2m", 'a') as end:
- end.write(footer)
+ async with open("./.temp/DailyForecast.i2m", 'a') as end:
+ await end.write(footer)
dom = xml.dom.minidom.parse("./.temp/DailyForecast.i2m")
pretty_xml_as_string = dom.toprettyxml(indent = " ")
- with open("./.temp/DailyForecast.i2m", "w") as g:
- g.write(pretty_xml_as_string[23:])
- g.close()
+ async with aiofiles.open("./.temp/DailyForecast.i2m", "w") as g:
+ await g.write(pretty_xml_as_string[23:])
+ await g.close()
files = []
commands = []