Fixed up record generators + new ones from Goldblaze

This commit is contained in:
April
2022-10-13 01:34:54 -07:00
parent 532fd39d40
commit 6537d392ac
7 changed files with 422 additions and 99 deletions

View File

@ -1,13 +1,26 @@
import requests
import bit
import gzip
import uuid
import os
import shutil
import xml.dom.minidom
tecciId = ['72462058']
zipCodes = ['81242']
import sys
sys.path.append("./py2lib")
sys.path.append("./Util")
sys.path.append("./records")
import bit
import MachineProductCfg as MPC
import LFRecord as LFR
tecciId = []
zipCodes = []
# Auto-grab the tecci and zip codes
for i in MPC.getPrimaryLocations():
tecciId.append(LFR.getCoopId(i))
zipCodes.append(LFR.getZip(i))
apiKey = '21d8a80b3d6b444998a80b3d6b1449d3'
@ -22,7 +35,7 @@ def getData(tecci, zipCode):
newData = data[48:-11]
print('Gathering data for location id ' + tecci)
print('[HOURLY FORECAST] Gathering data for location id ' + tecci)
#Write to .i2m file
i2Doc = '<HourlyForecast id="000000000" locationKey="' + str(tecci) + '" isWxscan="0">' + '' + newData + '<clientKey>' + str(tecci) + '</clientKey></HourlyForecast>'
@ -30,39 +43,40 @@ def getData(tecci, zipCode):
f.write(i2Doc)
f.close()
header = '<Data type="HourlyForecast">'
footer = '</Data>'
def makeDataFile():
header = '<Data type="HourlyForecast">'
footer = '</Data>'
with open("D:\\HourlyForecast.i2m", 'w') as doc:
doc.write(header)
with open("D:\\HourlyForecast.i2m", 'w') as doc:
doc.write(header)
for x, y in zip(tecciId, zipCodes):
getData(x, y)
with open("D:\\HourlyForecast.i2m", 'a') as end:
end.write(footer)
for x, y in zip(tecciId, zipCodes):
getData(x, y)
with open("D:\\HourlyForecast.i2m", 'a') as end:
end.write(footer)
dom = xml.dom.minidom.parse("D:\\HourlyForecast.i2m")
pretty_xml_as_string = dom.toprettyxml(indent = " ")
dom = xml.dom.minidom.parse("D:\\HourlyForecast.i2m")
pretty_xml_as_string = dom.toprettyxml(indent = " ")
with open("D:\\HourlyForecast.i2m", "w") as g:
g.write(pretty_xml_as_string[23:])
g.close()
with open("D:\\HourlyForecast.i2m", "w") as g:
g.write(pretty_xml_as_string[23:])
g.close()
files = []
commands = []
with open("D:\\HourlyForecast.i2m", 'rb') as f_in:
with gzip.open("D:\\HourlyForecast.gz", 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
files = []
commands = []
with open("D:\\HourlyForecast.i2m", 'rb') as f_in:
with gzip.open("D:\\HourlyForecast.gz", 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
gZipFile = "D:\\HourlyForecast.gz"
gZipFile = "D:\\HourlyForecast.gz"
files.append(gZipFile)
command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__HourlyForecast__,Feed=HourlyForecast)" /><GzipCompressedMsg fname="HourlyForecast" /></MSG>')
numFiles = len(files)
files.append(gZipFile)
command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__HourlyForecast__,Feed=HourlyForecast)" /><GzipCompressedMsg fname="HourlyForecast" /></MSG>')
numFiles = len(files)
bit.sendFile(files, commands, numFiles, 0)
bit.sendFile(files, commands, numFiles, 0)
os.remove("D:\\HourlyForecast.i2m")
os.remove("D:\\HourlyForecast.gz")
os.remove("D:\\HourlyForecast.i2m")
os.remove("D:\\HourlyForecast.gz")