mirror of
https://github.com/mewtek/i2ME-Legacy.git
synced 2025-05-11 00:57:31 -05:00
DailyForecast to asynchronous
This commit is contained in:
parent
bdbd707b32
commit
e557ebcacb
@ -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 = '<DailyForecast id="000000000" locationKey="' + str(tecci) + '" isWxscan="0">' + '' + newData + '<clientKey>' + str(tecci) + '</clientKey></DailyForecast>'
|
||||
|
||||
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 = '<Data type="DailyForecast">'
|
||||
footer = '</Data>'
|
||||
|
||||
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 = []
|
||||
|
Loading…
x
Reference in New Issue
Block a user