Move data to temp directory

This commit is contained in:
needlenose
2022-10-18 20:40:28 -07:00
parent 2fcf8a033e
commit e8554e81ed
12 changed files with 115 additions and 113 deletions

View File

@ -38,7 +38,7 @@ def getData(epaId, zipcode):
# Write to i2doc file
i2Doc = f'<AirQuality id="000000000" locationKey="{epaId}" isWxScan="0">' + '' + newData + f'<clientKey>{epaId}</clientKey></AirQuality>'
f = open("D:\\AirQuality.i2m", 'a')
f = open("./.temp/AirQuality.i2m", 'a')
f.write(i2Doc)
f.close()
@ -62,29 +62,29 @@ def writeData():
header = '<Data type="AirQuality">'
footer = "</Data>"
with open("D:\\AirQuality.i2m", 'w') as doc:
with open("./.temp/AirQuality.i2m", 'w') as doc:
doc.write(header)
for (x, y) in zip(workingEpaIds, zipCodes):
getData(x, y)
with open("D:\\AirQuality.i2m", 'a') as end:
with open("./.temp/AirQuality.i2m", 'a') as end:
end.write(footer)
dom = xml.dom.minidom.parse("D:\\AirQuality.i2m")
dom = xml.dom.minidom.parse("./.temp/AirQuality.i2m")
xmlPretty = dom.toprettyxml(indent = " ")
with open("D:\\AirQuality.i2m", 'w') as g:
with open("./.temp/AirQuality.i2m", 'w') as g:
g.write(xmlPretty[23:])
g.close()
files = []
commands = []
with open("D:\\AirQuality.i2m", 'rb') as f_in:
with gzip.open("D:\\AirQuality.gz", 'wb') as f_out:
with open("./.temp/AirQuality.i2m", 'rb') as f_in:
with gzip.open("./.temp/AirQuality.gz", 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
gZipFile = "D:\\AirQuality.gz"
gZipFile = "./.temp/AirQuality.gz"
files.append(gZipFile)
comand = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__AirQuality__,Feed=AirQuality)" /><GzipCompressedMsg fname="AirQuality" /></MSG>')
@ -92,8 +92,8 @@ def writeData():
bit.sendFile(files, commands, numFiles, 0)
os.remove("D:\\AirQuality.i2m")
os.remove("D:\\AirQuality.gz")
os.remove("./.temp/AirQuality.i2m")
os.remove("./.temp/AirQuality.gz")
except Exception as e:
l.error("DO NOT REPORT THE ERROR BELOW")
l.error("Failed to write an AirQuality record.")

View File

@ -40,7 +40,7 @@ def getData(airport):
# Write to i2doc file
i2Doc = f'<AirportDelays id="000000000" locationKey="{airport}" isWxScan="0">' + '' + newData + f'<clientKey>{airport}</clientKey></AirportDelays>'
f = open("D:\\AirportDelays.i2m", 'a')
f = open("./.temp/AirportDelays.i2m", 'a')
f.write(i2Doc)
f.close()
@ -64,29 +64,29 @@ def writeData():
header = '<Data type="AirportDelays">'
footer = "</Data>"
with open("D:\\AirportDelays.i2m", 'w') as doc:
with open("./.temp/AirportDelays.i2m", 'w') as doc:
doc.write(header)
for x in airportsWithDelays:
getData(x)
with open("D:\\AirportDelays.i2m", 'a') as end:
with open("./.temp/AirportDelays.i2m", 'a') as end:
end.write(footer)
dom = xml.dom.minidom.parse("D:\\AirportDelays.i2m")
dom = xml.dom.minidom.parse("./.temp/AirportDelays.i2m")
prettyXml = dom.toprettyxml(indent=" ")
with open("D:\\AirportDelays.i2m", 'w') as g:
with open("./.temp/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:
with open("./.temp/AirportDelays.i2m", 'rb') as f_in:
with gzip.open("./.temp/AirportDelays.gz", 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
gZipFile = "D:\\AirportDelays.gz"
gZipFile = "./.temp/AirportDelays.gz"
files.append(gZipFile)
comand = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__AirportDelays__,Feed=AirportDelays)" /><GzipCompressedMsg fname="AirportDelays" /></MSG>')
@ -94,7 +94,7 @@ def writeData():
bit.sendFile(files, commands, numFiles, 0)
os.remove("D:\\AirportDelays.i2m")
os.remove("D:\\AirportDelays.gz")
os.remove("./.temp/AirportDelays.i2m")
os.remove("./.temp/AirportDelays.gz")
else:
l.info("No airport delays found.")

View File

@ -304,7 +304,7 @@ def getAlerts(location):
alertMsg = '<BERecord id="0000" locationKey="' + location + '_' + x['phenomena'] + '_' + x['significance'] + '_' + x['eventTrackingNumber'] + '_' + x['officeCode'] + '" isWxscan="0"><action>NOT_USED</action><BEHdr><bPIL>' + x['productIdentifier'] + '</bPIL><bWMOHdr>NOT_USED</bWMOHdr><bEvent><eActionCd eActionPriority="' + str(x['messageTypeCode']) + '">' + Action + '</eActionCd><eOfficeId eOfficeNm="' + x['officeName'] + '">' + x['officeCode'] + '</eOfficeId><ePhenom>' + x['phenomena'] + '</ePhenom><eSgnfcnc>' + x['significance'] + '</eSgnfcnc><eETN>' + x['eventTrackingNumber'] + '</eETN><eDesc>' + x['eventDescription'] + '</eDesc><eStTmUTC>NOT_USED</eStTmUTC><eEndTmUTC>' + EndTimeUTC + '</eEndTmUTC><eSvrty>' + str(x['severityCode']) + '</eSvrty><eTWCIId>NOT_USED</eTWCIId><eExpTmUTC>' + expireTimeUTC + '</eExpTmUTC></bEvent><bLocations><bLocCd bLoc="' + x['areaName'] + '" bLocTyp="' + locationType + '">' + location + '</bLocCd><bStCd bSt="' + x['adminDistrict'] + '">' + x['adminDistrictCode'] + '</bStCd><bUTCDiff>NOT_USED</bUTCDiff><bTzAbbrv>NOT_USED</bTzAbbrv><bCntryCd>NOT_USED</bCntryCd></bLocations><bSgmtChksum>' + x['identifier'] + '</bSgmtChksum><procTm>' + processTime + '</procTm></BEHdr><BEData><bIssueTmUTC>' + issueTimeUtc + '</bIssueTmUTC><bHdln><bHdlnTxt>' + x['headlineText'] + '</bHdlnTxt>' + vocalCode + '</bHdln><bParameter>NOT_USED</bParameter><bNarrTxt bNarrTxtLang="en-US"><bLn>' + description + '</bLn></bNarrTxt><bSrchRslt>NOT_USED</bSrchRslt></BEData><clientKey>' + location + '_' + x['phenomena'] + '_' + x['significance'] + '_' + x['eventTrackingNumber'] + '_' + x['officeCode'] + '</clientKey></BERecord>'
#Append BERecord
with open('D:\\BERecord.xml', "a") as b:
with open('./.temp/BERecord.xml', "a") as b:
b.write(alertMsg)
b.close()
@ -317,39 +317,39 @@ def getAlerts(location):
# TODO: This should be converted into a function so it works better with async, that way we're not getting hung up on that time.sleep() call.
def makeRecord():
with open("D:\\BERecord.xml", 'a') as BERecord:
with open("./.temp/BERecord.xml", 'a') as BERecord:
BERecord.write('<Data type="BERecord">')
BERecord.close()
for z in zones:
getAlerts(z)
with open('D:\\BERecord.xml', 'a') as BERecord:
with open('./.temp/BERecord.xml', 'a') as BERecord:
BERecord.write("</Data>")
BERecord.close()
dom = xml.dom.minidom.parse("D:\\BERecord.xml")
dom = xml.dom.minidom.parse("./.temp/BERecord.xml")
pretty_xml_as_string = dom.toprettyxml(indent = " ")
with open("D:\\BERecord.i2m", 'w') as h:
with open("./.temp/BERecord.i2m", 'w') as h:
h.write(pretty_xml_as_string[23:])
h.close()
# If we don't need to send the i2 an alert, we don't need to gzip it.
if k > 0:
l.info("Sending alert(s) to the IntelliStar 2!")
with open("D:\\BERecord.i2m", 'rb') as f_in:
with gzip.open("D:\\BERecord.gz", 'wb') as f_out:
with open("./.temp/BERecord.i2m", 'rb') as f_in:
with gzip.open("./.temp/BERecord.gz", 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
files = []
commands = []
gZipFile = "D:\\BERecord.gz"
gZipFile = "./.temp/BERecord.gz"
files.append(gZipFile)
command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__BERecord__,Feed=BERecord)" /><GzipCompressedMsg fname="BERecord" /></MSG>')
bit.sendFile(files, commands, 1, 0)
os.remove(gZipFile)
k = 0
os.remove("D:\\BERecord.xml")
os.remove("./.temp/BERecord.xml")

View File

@ -45,7 +45,7 @@ def getData(coopId, geocode):
#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 = open("./.temp/Breathing.i2m", "a")
f.write(i2Doc)
f.close()
@ -55,30 +55,30 @@ def makeDataFile():
header = '<Data type="Breathing">'
footer = '</Data>'
with open("D:\\Breathing.i2m", 'w') as doc:
with open("./.temp/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:
with open("./.temp/Breathing.i2m", 'a') as end:
end.write(footer)
dom = xml.dom.minidom.parse("D:\\Breathing.i2m")
dom = xml.dom.minidom.parse("./.temp/Breathing.i2m")
pretty_xml_as_string = dom.toprettyxml(indent = " ")
with open("D:\\Breathing.i2m", "w") as g:
with open("./.temp/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:
with open("./.temp/Breathing.i2m", 'rb') as f_in:
with gzip.open("./.temp/Breathing.gz", 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
gZipFile = "D:\\Breathing.gz"
gZipFile = "./.temp/Breathing.gz"
files.append(gZipFile)
command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__Breathing__,Feed=Breathing)" /><GzipCompressedMsg fname="Breathing" /></MSG>')
@ -86,5 +86,5 @@ def makeDataFile():
bit.sendFile(files, commands, numFiles, 0)
os.remove("D:\\Breathing.i2m")
os.remove("D:\\Breathing.gz")
os.remove("./.temp/Breathing.i2m")
os.remove("./.temp/Breathing.gz")

View File

@ -45,7 +45,7 @@ def getData(tecci, zipCode):
i2Doc = '<CurrentObservations id="000000000" locationKey="' + str(tecci) + '" isWxscan="0">' + '' + newData + '<clientKey>' + str(tecci) + '</clientKey></CurrentObservations>'
f = open("D:\\CurrentObservations.i2m", "a")
f = open("./.temp/CurrentObservations.i2m", "a")
f.write(i2Doc)
f.close()
@ -54,30 +54,30 @@ def makeDataFile():
header = '<Data type="CurrentObservations">'
footer = '</Data>'
with open("D:\\CurrentObservations.i2m", 'w') as doc:
with open("./.temp/CurrentObservations.i2m", 'w') as doc:
doc.write(header)
for x, y in zip(tecciId, zipCodes):
getData(x, y)
with open("D:\\CurrentObservations.i2m", 'a') as end:
with open("./.temp/CurrentObservations.i2m", 'a') as end:
end.write(footer)
dom = xml.dom.minidom.parse("D:\\CurrentObservations.i2m")
dom = xml.dom.minidom.parse("./.temp/CurrentObservations.i2m")
pretty_xml_as_string = dom.toprettyxml(indent = " ")
with open("D:\\CurrentObservations.i2m", "w") as g:
with open("./.temp/CurrentObservations.i2m", "w") as g:
g.write(pretty_xml_as_string[23:])
g.close()
files = []
commands = []
with open("D:\\CurrentObservations.i2m", 'rb') as f_in:
with gzip.open("D:\\CurrentObservations.gz", 'wb') as f_out:
with open("./.temp/CurrentObservations.i2m", 'rb') as f_in:
with gzip.open("./.temp/CurrentObservations.gz", 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
gZipFile = "D:\\CurrentObservations.gz"
gZipFile = "./.temp/CurrentObservations.gz"
files.append(gZipFile)
command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__CurrentObservations__,Feed=CurrentObservations)" /><GzipCompressedMsg fname="CurrentObservations" /></MSG>')
@ -85,5 +85,5 @@ def makeDataFile():
bit.sendFile(files, commands, numFiles, 0)
os.remove("D:\\CurrentObservations.i2m")
os.remove("D:\\CurrentObservations.gz")
os.remove("./.temp/CurrentObservations.i2m")
os.remove("./.temp/CurrentObservations.gz")

View File

@ -42,7 +42,7 @@ 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("D:\\DailyForecast.i2m", "a")
f = open("./.temp/DailyForecast.i2m", "a")
f.write(i2Doc)
f.close()
@ -52,30 +52,30 @@ def makeDataFile():
header = '<Data type="DailyForecast">'
footer = '</Data>'
with open("D:\\DailyForecast.i2m", 'w') as doc:
with open("./.temp/DailyForecast.i2m", 'w') as doc:
doc.write(header)
for x, y in zip(tecciId, zipCodes):
getData(x, y)
with open("D:\\DailyForecast.i2m", 'a') as end:
with open("./.temp/DailyForecast.i2m", 'a') as end:
end.write(footer)
dom = xml.dom.minidom.parse("D:\\DailyForecast.i2m")
dom = xml.dom.minidom.parse("./.temp/DailyForecast.i2m")
pretty_xml_as_string = dom.toprettyxml(indent = " ")
with open("D:\\DailyForecast.i2m", "w") as g:
with open("./.temp/DailyForecast.i2m", "w") as g:
g.write(pretty_xml_as_string[23:])
g.close()
files = []
commands = []
with open("D:\\DailyForecast.i2m", 'rb') as f_in:
with gzip.open("D:\\DailyForecast.gz", 'wb') as f_out:
with open("./.temp/DailyForecast.i2m", 'rb') as f_in:
with gzip.open("./.temp/DailyForecast.gz", 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
gZipFile = "D:\\DailyForecast.gz"
gZipFile = "./.temp/DailyForecast.gz"
files.append(gZipFile)
command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__DailyForecast__,Feed=DailyForecast)" /><GzipCompressedMsg fname="DailyForecast" /></MSG>')
@ -83,5 +83,5 @@ def makeDataFile():
bit.sendFile(files, commands, numFiles, 0)
os.remove("D:\\DailyForecast.i2m")
os.remove("D:\\DailyForecast.gz")
os.remove("./.temp/DailyForecast.i2m")
os.remove("./.temp/DailyForecast.gz")

View File

@ -42,7 +42,7 @@ def getData(tecci, zipCode):
#Write to .i2m file
i2Doc = '<HourlyForecast id="000000000" locationKey="' + str(tecci) + '" isWxscan="0">' + '' + newData + '<clientKey>' + str(tecci) + '</clientKey></HourlyForecast>'
f = open("D:\\HourlyForecast.i2m", "a")
f = open("./.temp/HourlyForecast.i2m", "a")
f.write(i2Doc)
f.close()
@ -51,30 +51,30 @@ def makeDataFile():
header = '<Data type="HourlyForecast">'
footer = '</Data>'
with open("D:\\HourlyForecast.i2m", 'w') as doc:
with open("./.temp/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:
with open("./.temp/HourlyForecast.i2m", 'a') as end:
end.write(footer)
dom = xml.dom.minidom.parse("D:\\HourlyForecast.i2m")
dom = xml.dom.minidom.parse("./.temp/HourlyForecast.i2m")
pretty_xml_as_string = dom.toprettyxml(indent = " ")
with open("D:\\HourlyForecast.i2m", "w") as g:
with open("./.temp/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:
with open("./.temp/HourlyForecast.i2m", 'rb') as f_in:
with gzip.open("./.temp/HourlyForecast.gz", 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
gZipFile = "D:\\HourlyForecast.gz"
gZipFile = "./.temp/HourlyForecast.gz"
files.append(gZipFile)
command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__HourlyForecast__,Feed=HourlyForecast)" /><GzipCompressedMsg fname="HourlyForecast" /></MSG>')
@ -82,5 +82,5 @@ def makeDataFile():
bit.sendFile(files, commands, numFiles, 0)
os.remove("D:\\HourlyForecast.i2m")
os.remove("D:\\HourlyForecast.gz")
os.remove("./.temp/HourlyForecast.i2m")
os.remove("./.temp/HourlyForecast.gz")

View File

@ -46,7 +46,7 @@ def getData(pollenId, geocode):
#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 = open("./.temp/PollenForecast.i2m", "a")
f.write(i2Doc)
f.close()
@ -56,30 +56,30 @@ def makeDataFile():
header = '<Data type="PollenForecast">'
footer = '</Data>'
with open("D:\\PollenForecast.i2m", 'w') as doc:
with open("./.temp/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:
with open("./.temp/PollenForecast.i2m", 'a') as end:
end.write(footer)
dom = xml.dom.minidom.parse("D:\\PollenForecast.i2m")
dom = xml.dom.minidom.parse("./.temp/PollenForecast.i2m")
pretty_xml_as_string = dom.toprettyxml(indent = " ")
with open("D:\\PollenForecast.i2m", "w") as g:
with open("./.temp/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:
with open("./.temp/PollenForecast.i2m", 'rb') as f_in:
with gzip.open("./.temp/PollenForecast.gz", 'wb') as f_out:
shutil.copyfileobj(f_in, f_out)
gZipFile = "D:\\PollenForecast.gz"
gZipFile = "./.temp/PollenForecast.gz"
files.append(gZipFile)
command = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__PollenForecast__,Feed=PollenForecast)" /><GzipCompressedMsg fname="PollenForecast" /></MSG>')
@ -87,5 +87,5 @@ def makeDataFile():
bit.sendFile(files, commands, numFiles, 0)
os.remove("D:\\PollenForecast.i2m")
os.remove("D:\\PollenForecast.gz")
os.remove("./.temp/PollenForecast.i2m")
os.remove("./.temp/PollenForecast.gz")