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
No known key found for this signature in database
GPG Key ID: 17A9A017FAA4DE5E
7 changed files with 422 additions and 99 deletions

View File

@ -32,39 +32,50 @@ def getData(epaId, zipcode):
newData = data[57:-11] newData = data[57:-11]
# Write to i2doc file # Write to i2doc file
i2Doc = f'<AirQuality id="000000000" locationKey="{epaId}" isWxScan=0>' + '' + newData + f'<clientKey="{epaId}"></AirQuality>' i2Doc = f'<AirQuality id="000000000" locationKey="{epaId}" isWxScan="0">' + '' + newData + f'<clientKey>{epaId}</clientKey></AirQuality>'
f = open("D:\\AirQuality.xml", 'a') f = open("D:\\AirQuality.i2m", 'a')
f.write(i2Doc) f.write(i2Doc)
f.close() f.close()
def writeData(): def writeData():
useData = False
workingEpaIds = []
for i in epaIds:
if i == None:
print(f"No EPA ID found for location -- Skipping.")
else:
print(f"EPA ID found for location! Writing data for Air Quality.")
workingEpaIds.append(i)
useData = True
# Check to see if we even have EPA ids, as some areas don't have air quality reports # Check to see if we even have EPA ids, as some areas don't have air quality reports
if (epaIds != None or epaIds != ['']): if (useData):
header = '<Data type="AirQuality">' header = '<Data type="AirQuality">'
footer = "</Data>" footer = "</Data>"
with open("D:\\AirQuality.i2m", 'w') as doc: with open("D:\\AirQuality.i2m", 'w') as doc:
doc.write(header) doc.write(header)
for (x, y) in zip(epaIds, zipCodes): for (x, y) in zip(workingEpaIds, zipCodes):
getData(x, y) getData(x, y)
with open("D:\\AirQuality.i2m", 'a') as end: with open("D:\\AirQuality.i2m", 'a') as end:
end.write(footer) end.write(footer)
dom = xml.dom.minidom.parse("D:\\AirQuality.i2m") dom = xml.dom.minidom.parse("D:\\AirQuality.i2m")
xml = dom.toprettyxml(indent = " ") xmlPretty = dom.toprettyxml(indent = " ")
with open("D:\\AirQuality.i2m", 'w') as g: with open("D:\\AirQuality.i2m", 'w') as g:
g.write(xml) g.write(xmlPretty[23:])
g.close() g.close()
files = [] files = []
commands = [] commands = []
with open("D:\\AirQuality.i2m", 'rb') as f_in: with open("D:\\AirQuality.i2m", 'rb') as f_in:
with gzip.open("D:\\AirQuality.xml", 'wb') as f_out: with gzip.open("D:\\AirQuality.gz", 'wb') as f_out:
shutil.copyfileobj(f_in, f_out) shutil.copyfileobj(f_in, f_out)
gZipFile = "D:\\AirQuality.gz" gZipFile = "D:\\AirQuality.gz"
@ -78,7 +89,7 @@ def writeData():
os.remove("D:\\AirQuality.i2m") os.remove("D:\\AirQuality.i2m")
os.remove("D:\\AirQuality.gz") os.remove("D:\\AirQuality.gz")
else: else:
print("Ignoring AirQuality data collection -- No epaIds for primary locations.") print("Ignoring AirQuality data collection -- No working EPA Ids.")

View File

@ -0,0 +1,96 @@
import requests
import gzip
import os
import shutil
import xml.dom.minidom
import sys
sys.path.append("./py2lib")
sys.path.append("./Util")
sys.path.append("./records")
import bit
import MachineProductCfg as MPC
import LFRecord as LFR
locationIds = []
zipCodes = []
airports = []
for i in MPC.getPrimaryLocations():
locationIds.append(LFR.getCoopId(i))
zipCodes.append(LFR.getZip(i))
airports = MPC.getAirportCodes()
print(airports)
apiKey = '21d8a80b3d6b444998a80b3d6b1449d3'
def getData(airport):
url = f"https://api.weather.com/v1/airportcode/{airport}/airport/delays.xml?language=en-US&apiKey={apiKey}"
res = requests.get(url=url)
data = res.text
newData = data[48:-11]
# Write to i2doc file
i2Doc = f'<AirportDelays id="000000000" locationKey="{airport}" isWxScan="0">' + '' + newData + f'<clientKey>{airport}</clientKey></AirportDelays>'
print(f"[AIRPORT DELAYS] Writing airport delay data for {airport}")
f = open("D:\\AirportDelays.i2m", 'a')
f.write(i2Doc)
f.close()
def writeData():
useData = False
airportsWithDelays = []
for x in airports:
# Do a quick check to see if the airport in question has a delay or not
res = requests.get(f"https://api.weather.com/v1/airportcode/{x}/airport/delays.xml?language=en-US&apiKey={apiKey}")
if (res.status_code != 200):
print(f"[AIRPORT DELAYS] No delays for {x} found, skipping..")
else:
airportsWithDelays.append(x)
print(f"[AIRPORT DELAYS] {x} has a delay! Writing a file..")
useData = True
if (useData):
header = '<Data type="AirportDelays">'
footer = "</Data>"
with open("D:\\AirportDelays.i2m", 'w') as doc:
doc.write(header)
for x in airportsWithDelays:
getData(x)
with open("D:\\AirportDelays.i2m", 'a') as end:
end.write(footer)
dom = xml.dom.minidom.parse("D:\\AirportDelays.i2m")
prettyXml = dom.toprettyxml(indent=" ")
with open("D:\\AirportDelays.i2m", 'w') as g:
g.write(prettyXml)
g.close()
files = []
commands = []
with open("D:\\AirportDelays.i2m", 'rb') as f_in:
with gzip.open("D:\\AirportDelays.gz", 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
gZipFile = "D:\\AirportDelays.gz"
files.append(gZipFile)
comand = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__AirportDelays__,Feed=AirportDelays)" /><GzipCompressedMsg fname="AirportDelays" /></MSG>')
numFiles = len(files)
bit.sendFile(files, commands, numFiles, 0)
os.remove("D:\\AirportDelays.i2m")
os.remove("D:\\AirportDelays.gz")
else:
print("[AIRPORT DELAYS] Not writing AirportDelays -- Either no delays found, or the API is broken.")

View File

@ -0,0 +1,86 @@
import requests
import sys
import gzip
import uuid
import os
import shutil
import xml.dom.minidom
sys.path.append("./py2lib")
sys.path.append("./Util")
sys.path.append("./records")
import bit
import MachineProductCfg as MPC
import LFRecord as LFR
coopIds = []
geocodes = []
# Auto-grab the tecci and zip codes
for i in MPC.getPrimaryLocations():
coopIds.append(LFR.getCoopId(i))
geocodes.append(LFR.getLatLong(i).replace('/', ','))
print(coopIds, geocodes)
apiKey = '21d8a80b3d6b444998a80b3d6b1449d3'
def getData(coopId, geocode):
fetchUrl = f"https://api.weather.com/v2/indices/breathing/daypart/7day?geocode={geocode}&language=en-US&format=xml&apiKey={apiKey}"
#Fetch data
response = requests.get(fetchUrl)
data = response.text
newData = data[63:-26]
print('[BREATHING] Gathering data for location id ' + coopId)
#Write to .i2m file
i2Doc = '<Breathing id="000000000" locationKey="' + str(coopId) + '" isWxscan="0">' + '' + newData + '<clientKey>' + str(coopId) + '</clientKey></Breathing>'
f = open("D:\\Breathing.i2m", "a")
f.write(i2Doc)
f.close()
def makeDataFile():
header = '<Data type="Breathing">'
footer = '</Data>'
with open("D:\\Breathing.i2m", 'w') as doc:
doc.write(header)
for x, y in zip(coopIds, geocodes):
getData(x, y)
with open("D:\\Breathing.i2m", 'a') as end:
end.write(footer)
dom = xml.dom.minidom.parse("D:\\Breathing.i2m")
pretty_xml_as_string = dom.toprettyxml(indent = " ")
with open("D:\\Breathing.i2m", "w") as g:
g.write(pretty_xml_as_string[23:])
g.close()
files = []
commands = []
with open("D:\\Breathing.i2m", 'rb') as f_in:
with gzip.open("D:\\Breathing.gz", 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
gZipFile = "D:\\Breathing.gz"
files.append(gZipFile)
command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__Breathing__,Feed=Breathing)" /><GzipCompressedMsg fname="Breathing" /></MSG>')
numFiles = len(files)
bit.sendFile(files, commands, numFiles, 0)
os.remove("D:\\Breathing.i2m")
os.remove("D:\\Breathing.gz")

View File

@ -1,13 +1,27 @@
import requests import requests
import bit import py2Lib.bit as bit
import gzip import gzip
import uuid import uuid
import os import os
import shutil import shutil
import xml.dom.minidom import xml.dom.minidom
tecciId = ['T72462058'] import sys
zipCodes = ['81242'] 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("T" + LFR.getCoopId(i))
zipCodes.append(LFR.getZip(i))
apiKey = '21d8a80b3d6b444998a80b3d6b1449d3' apiKey = '21d8a80b3d6b444998a80b3d6b1449d3'
@ -23,7 +37,7 @@ def getData(tecci, zipCode):
newData = data[67:-30] newData = data[67:-30]
print('Gathering data for location id ' + tecci) print('[CURRENT CONDITIONS] Gathering data for location id ' + tecci)
#Write to .i2m file #Write to .i2m file
i2Doc = '<CurrentObservations id="000000000" locationKey="' + str(tecci) + '" isWxscan="0">' + '' + newData + '<clientKey>' + str(tecci) + '</clientKey></CurrentObservations>' i2Doc = '<CurrentObservations id="000000000" locationKey="' + str(tecci) + '" isWxscan="0">' + '' + newData + '<clientKey>' + str(tecci) + '</clientKey></CurrentObservations>'
@ -32,39 +46,40 @@ def getData(tecci, zipCode):
f.write(i2Doc) f.write(i2Doc)
f.close() f.close()
header = '<Data type="CurrentObservations">' def makeDataFile():
footer = '</Data>' header = '<Data type="CurrentObservations">'
footer = '</Data>'
with open("D:\\CurrentObservations.i2m", 'w') as doc: with open("D:\\CurrentObservations.i2m", 'w') as doc:
doc.write(header) 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("D:\\CurrentObservations.i2m", 'a') as end: with open("D:\\CurrentObservations.i2m", 'a') as end:
end.write(footer) end.write(footer)
dom = xml.dom.minidom.parse("D:\\CurrentObservations.i2m") dom = xml.dom.minidom.parse("D:\\CurrentObservations.i2m")
pretty_xml_as_string = dom.toprettyxml(indent = " ") pretty_xml_as_string = dom.toprettyxml(indent = " ")
with open("D:\\CurrentObservations.i2m", "w") as g: with open("D:\\CurrentObservations.i2m", "w") as g:
g.write(pretty_xml_as_string[23:]) g.write(pretty_xml_as_string[23:])
g.close() g.close()
files = [] files = []
commands = [] commands = []
with open("D:\\CurrentObservations.i2m", 'rb') as f_in: with open("D:\\CurrentObservations.i2m", 'rb') as f_in:
with gzip.open("D:\\CurrentObservations.gz", 'wb') as f_out: with gzip.open("D:\\CurrentObservations.gz", 'wb') as f_out:
shutil.copyfileobj(f_in, f_out) shutil.copyfileobj(f_in, f_out)
gZipFile = "D:\\CurrentObservations.gz" gZipFile = "D:\\CurrentObservations.gz"
files.append(gZipFile) files.append(gZipFile)
command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__CurrentObservations__,Feed=CurrentObservations)" /><GzipCompressedMsg fname="CurrentObservations" /></MSG>') command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__CurrentObservations__,Feed=CurrentObservations)" /><GzipCompressedMsg fname="CurrentObservations" /></MSG>')
numFiles = len(files) numFiles = len(files)
bit.sendFile(files, commands, numFiles, 0) bit.sendFile(files, commands, numFiles, 0)
os.remove("D:\\CurrentObservations.i2m") os.remove("D:\\CurrentObservations.i2m")
os.remove("D:\\CurrentObservations.gz") os.remove("D:\\CurrentObservations.gz")

View File

@ -1,13 +1,26 @@
import requests import requests
import bit import sys
import gzip import gzip
import uuid import uuid
import os import os
import shutil import shutil
import xml.dom.minidom import xml.dom.minidom
tecciId = ['72462058'] sys.path.append("./py2lib")
zipCodes = ['81242'] 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' apiKey = '21d8a80b3d6b444998a80b3d6b1449d3'
@ -22,7 +35,7 @@ def getData(tecci, zipCode):
newData = data[61:-24] newData = data[61:-24]
print('Gathering data for location id ' + tecci) print('[DAILY FORECAST] Gathering data for location id ' + tecci)
#Write to .i2m file #Write to .i2m file
i2Doc = '<DailyForecast id="000000000" locationKey="' + str(tecci) + '" isWxscan="0">' + '' + newData + '<clientKey>' + str(tecci) + '</clientKey></DailyForecast>' i2Doc = '<DailyForecast id="000000000" locationKey="' + str(tecci) + '" isWxscan="0">' + '' + newData + '<clientKey>' + str(tecci) + '</clientKey></DailyForecast>'
@ -30,39 +43,41 @@ def getData(tecci, zipCode):
f.write(i2Doc) f.write(i2Doc)
f.close() f.close()
header = '<Data type="DailyForecast">'
footer = '</Data>'
with open("D:\\DailyForecast.i2m", 'w') as doc: def makeDataFile():
doc.write(header) header = '<Data type="DailyForecast">'
footer = '</Data>'
for x, y in zip(tecciId, zipCodes): with open("D:\\DailyForecast.i2m", 'w') as doc:
getData(x, y) doc.write(header)
with open("D:\\DailyForecast.i2m", 'a') as end: for x, y in zip(tecciId, zipCodes):
end.write(footer) getData(x, y)
with open("D:\\DailyForecast.i2m", 'a') as end:
end.write(footer)
dom = xml.dom.minidom.parse("D:\\DailyForecast.i2m") dom = xml.dom.minidom.parse("D:\\DailyForecast.i2m")
pretty_xml_as_string = dom.toprettyxml(indent = " ") pretty_xml_as_string = dom.toprettyxml(indent = " ")
with open("D:\\DailyForecast.i2m", "w") as g: with open("D:\\DailyForecast.i2m", "w") as g:
g.write(pretty_xml_as_string[23:]) g.write(pretty_xml_as_string[23:])
g.close() g.close()
files = [] files = []
commands = [] commands = []
with open("D:\\DailyForecast.i2m", 'rb') as f_in: with open("D:\\DailyForecast.i2m", 'rb') as f_in:
with gzip.open("D:\\DailyForecast.gz", 'wb') as f_out: with gzip.open("D:\\DailyForecast.gz", 'wb') as f_out:
shutil.copyfileobj(f_in, f_out) shutil.copyfileobj(f_in, f_out)
gZipFile = "D:\\DailyForecast.gz" gZipFile = "D:\\DailyForecast.gz"
files.append(gZipFile) files.append(gZipFile)
command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__DailyForecast__,Feed=DailyForecast)" /><GzipCompressedMsg fname="DailyForecast" /></MSG>') command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__DailyForecast__,Feed=DailyForecast)" /><GzipCompressedMsg fname="DailyForecast" /></MSG>')
numFiles = len(files) numFiles = len(files)
bit.sendFile(files, commands, numFiles, 0) bit.sendFile(files, commands, numFiles, 0)
os.remove("D:\\DailyForecast.i2m") os.remove("D:\\DailyForecast.i2m")
os.remove("D:\\DailyForecast.gz") os.remove("D:\\DailyForecast.gz")

View File

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

View File

@ -0,0 +1,86 @@
import requests
import sys
import gzip
import uuid
import os
import shutil
import xml.dom.minidom
sys.path.append("./py2lib")
sys.path.append("./Util")
sys.path.append("./records")
import bit
import MachineProductCfg as MPC
import LFRecord as LFR
pollenIds = []
geocodes = []
# Auto-grab the tecci and zip codes
for i in MPC.getPrimaryLocations():
pollenIds.append(LFR.getPollenInfo(i))
geocodes.append(LFR.getLatLong(i).replace('/', ','))
print(pollenIds, geocodes)
apiKey = '21d8a80b3d6b444998a80b3d6b1449d3'
def getData(pollenId, geocode):
fetchUrl = f"https://api.weather.com/v2/indices/pollen/daypart/7day?geocode={geocode}&language=en-US&format=xml&apiKey={apiKey}"
#Fetch data
response = requests.get(fetchUrl)
data = response.text
newData = data[63:-26]
print('[POLLEN FORECAST] Gathering data for location id ' + pollenId)
#Write to .i2m file
i2Doc = '<PollenForecast id="000000000" locationKey="' + str(pollenId) + '" isWxscan="0">' + '' + newData + '<clientKey>' + str(pollenId) + '</clientKey></PollenForecast>'
f = open("D:\\PollenForecast.i2m", "a")
f.write(i2Doc)
f.close()
def makeDataFile():
header = '<Data type="PollenForecast">'
footer = '</Data>'
with open("D:\\PollenForecast.i2m", 'w') as doc:
doc.write(header)
for x, y in zip(pollenIds, geocodes):
getData(x, y)
with open("D:\\PollenForecast.i2m", 'a') as end:
end.write(footer)
dom = xml.dom.minidom.parse("D:\\PollenForecast.i2m")
pretty_xml_as_string = dom.toprettyxml(indent = " ")
with open("D:\\PollenForecast.i2m", "w") as g:
g.write(pretty_xml_as_string[23:])
g.close()
files = []
commands = []
with open("D:\\PollenForecast.i2m", 'rb') as f_in:
with gzip.open("D:\\PollenForecast.gz", 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
gZipFile = "D:\\PollenForecast.gz"
files.append(gZipFile)
command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__PollenForecast__,Feed=PollenForecast)" /><GzipCompressedMsg fname="PollenForecast" /></MSG>')
numFiles = len(files)
bit.sendFile(files, commands, numFiles, 0)
os.remove("D:\\PollenForecast.i2m")
os.remove("D:\\PollenForecast.gz")