mirror of
https://github.com/mewtek/i2ME-Legacy.git
synced 2025-05-15 02:31:05 -05:00
Exception handling for writing AirQuality
This commit is contained in:
parent
1ff7731501
commit
f7314f286f
@ -53,41 +53,44 @@ def writeData():
|
|||||||
|
|
||||||
# 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 (useData):
|
if (useData):
|
||||||
header = '<Data type="AirQuality">'
|
try:
|
||||||
footer = "</Data>"
|
header = '<Data type="AirQuality">'
|
||||||
|
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(workingEpaIds, 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")
|
||||||
xmlPretty = 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(xmlPretty[23:])
|
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.gz", '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"
|
||||||
|
|
||||||
files.append(gZipFile)
|
files.append(gZipFile)
|
||||||
comand = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__AirQuality__,Feed=AirQuality)" /><GzipCompressedMsg fname="AirQuality" /></MSG>')
|
comand = commands.append('<MSG><Exec workRequest="storeData(File={0},QGROUP=__AirQuality__,Feed=AirQuality)" /><GzipCompressedMsg fname="AirQuality" /></MSG>')
|
||||||
numFiles = len(files)
|
numFiles = len(files)
|
||||||
|
|
||||||
bit.sendFile(files, commands, numFiles, 0)
|
bit.sendFile(files, commands, numFiles, 0)
|
||||||
|
|
||||||
os.remove("D:\\AirQuality.i2m")
|
os.remove("D:\\AirQuality.i2m")
|
||||||
os.remove("D:\\AirQuality.gz")
|
os.remove("D:\\AirQuality.gz")
|
||||||
|
except Exception as e:
|
||||||
|
print("AirQuality failed to write, problably was expired and was sticking around in the IBM api.")
|
||||||
else:
|
else:
|
||||||
print("Ignoring AirQuality data collection -- No working EPA Ids.")
|
print("Ignoring AirQuality data collection -- No working EPA Ids.")
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user