mirror of
https://github.com/mewtek/i2ME-Legacy.git
synced 2025-05-17 03:20:23 -05:00
Clean up the BERecord generator
This commit is contained in:
parent
a7f21d5c20
commit
591f189a52
@ -294,8 +294,11 @@ async def makeRadarImages():
|
|||||||
rmtree(f'tiles/{times[i]}')
|
rmtree(f'tiles/{times[i]}')
|
||||||
|
|
||||||
# Composite images for the i2
|
# Composite images for the i2
|
||||||
|
imgsProcessed = 0
|
||||||
for img in framesToComposite:
|
for img in framesToComposite:
|
||||||
|
imgsProcessed += 1
|
||||||
l.debug("Attempting to composite " + img)
|
l.debug("Attempting to composite " + img)
|
||||||
|
l.info(f"Processing radar frame {imgsProcessed} / 36")
|
||||||
|
|
||||||
# Crop the radar images something that the i2 will actually take
|
# Crop the radar images something that the i2 will actually take
|
||||||
img_raw = wandImage(filename=img)
|
img_raw = wandImage(filename=img)
|
||||||
|
@ -8,8 +8,12 @@ import pytz
|
|||||||
import xml.dom.minidom
|
import xml.dom.minidom
|
||||||
import shutil
|
import shutil
|
||||||
import gzip
|
import gzip
|
||||||
|
import logging,coloredlogs
|
||||||
import py2Lib.bit as bit
|
import py2Lib.bit as bit
|
||||||
|
|
||||||
|
l = logging.getLogger(__name__)
|
||||||
|
coloredlogs.install()
|
||||||
|
|
||||||
#Zones/Counties to fetch alerts for
|
#Zones/Counties to fetch alerts for
|
||||||
zones = getZones()
|
zones = getZones()
|
||||||
|
|
||||||
@ -17,11 +21,6 @@ zones = getZones()
|
|||||||
headlineApiKey = '21d8a80b3d6b444998a80b3d6b1449d3'
|
headlineApiKey = '21d8a80b3d6b444998a80b3d6b1449d3'
|
||||||
detailsApiKey = '21d8a80b3d6b444998a80b3d6b1449d3'
|
detailsApiKey = '21d8a80b3d6b444998a80b3d6b1449d3'
|
||||||
|
|
||||||
#Where does this script live? Put path below.
|
|
||||||
#Sorry I'm too lazy to program this script figure it out itself.
|
|
||||||
#TODO: Find the path automatically
|
|
||||||
path = 'D:\\PythonScripts\\Alerts'
|
|
||||||
|
|
||||||
k = 0
|
k = 0
|
||||||
def getAlerts(location):
|
def getAlerts(location):
|
||||||
global k
|
global k
|
||||||
@ -65,7 +64,7 @@ def getAlerts(location):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
#Alright lets map our headline variables.
|
#Alright lets map our headline variables.
|
||||||
print('Found Alert for ' + location + '\n')
|
l.debug('Found Alert for ' + location + '\n')
|
||||||
dataH = response.json()
|
dataH = response.json()
|
||||||
alertsRoot = dataH['alerts']
|
alertsRoot = dataH['alerts']
|
||||||
|
|
||||||
@ -91,11 +90,11 @@ def getAlerts(location):
|
|||||||
locationType = 'Z'
|
locationType = 'Z'
|
||||||
|
|
||||||
#theIdent = str(Identifier)
|
#theIdent = str(Identifier)
|
||||||
thecheck = open(path + '\\Output\\alertmanifest.txt', "r")
|
thecheck = open('alertmanifest.txt', "r")
|
||||||
check = thecheck.read()
|
check = thecheck.read()
|
||||||
|
|
||||||
if check.find(Identifier) != -1:
|
if check.find(Identifier) != -1:
|
||||||
print("Alert already sent...")
|
l.debug("Alert already sent...")
|
||||||
return
|
return
|
||||||
k += 1 #We have an alert to send!
|
k += 1 #We have an alert to send!
|
||||||
|
|
||||||
@ -301,55 +300,52 @@ 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>'
|
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
|
#Append BERecord
|
||||||
with open(path + '\\Output\\BERecord.xml', "a") as b:
|
with open('D:\\BERecord.xml', "a") as b:
|
||||||
b.write(alertMsg)
|
b.write(alertMsg)
|
||||||
b.close()
|
b.close()
|
||||||
|
|
||||||
#Add our alert to the manifest so we don't keep sending in the same alert every 60 seconds unless an update is issued.
|
#Add our alert to the manifest so we don't keep sending in the same alert every 60 seconds unless an update is issued.
|
||||||
with open(path + '\\Output\\alertmanifest.txt', "a") as c:
|
with open('alertmanifest.txt', "a") as c:
|
||||||
c.write('\n' + location + '_' + x['phenomena'] + '_' + x['significance'] + '_' + str(x['processTimeUTC']))
|
c.write('\n' + location + '_' + x['phenomena'] + '_' + x['significance'] + '_' + str(x['processTimeUTC']))
|
||||||
c.close()
|
c.close()
|
||||||
|
|
||||||
|
|
||||||
# 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.
|
# 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.
|
||||||
|
|
||||||
# n = 0
|
def makeRecord():
|
||||||
# while n==0:
|
with open("D:\\BERecord.xml", 'a') as BERecord:
|
||||||
# #Start our XML File
|
BERecord.write('<Data type="BERecord>')
|
||||||
# with open(path + '\\Output\\BERecord.xml', "w") as e:
|
BERecord.close()
|
||||||
# e.write('<Data type="BERecord">')
|
|
||||||
# e.close()
|
|
||||||
# for i in interestList:
|
|
||||||
# getAlerts(i)
|
|
||||||
# #Close our XML File
|
|
||||||
# with open(path + '\\Output\\BERecord.xml', "a") as d:
|
|
||||||
# d.write('</Data>')
|
|
||||||
# d.close()
|
|
||||||
# dom = xml.dom.minidom.parse(path + '\\Output\\BERecord.xml')
|
|
||||||
# pretty_xml_as_string = dom.toprettyxml(indent = " ")
|
|
||||||
|
|
||||||
# with open(path + '\\Output\\BERecord.i2m', "w") as h:
|
for z in zones:
|
||||||
# h.write(pretty_xml_as_string[23:])
|
getAlerts(z)
|
||||||
# h.close()
|
|
||||||
# if k > 0:
|
|
||||||
# with open(path + '\\Output\\BERecord.i2m', 'rb') as f_in:
|
|
||||||
# with gzip.open(path + '\\Output\\BERecord.gz', 'wb') as f_out:
|
|
||||||
# shutil.copyfileobj(f_in, f_out)
|
|
||||||
|
|
||||||
# files = []
|
with open('D:\\BERecord.xml', 'a') as BERecord:
|
||||||
# commands = []
|
BERecord.write("</Data>")
|
||||||
# gZipFile = path + '\\Output\\BERecord.gz'
|
BERecord.close()
|
||||||
# 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(path + '\\Output\\BERecord.xml')
|
|
||||||
# #os.remove(path + '\\Output\\BERecord.i2m')
|
|
||||||
|
|
||||||
# print('Will sleep for 60 seconds...\n')
|
dom = xml.dom.minidom.parse("D:\\BERecord.xml")
|
||||||
# time.sleep(60)
|
pretty_xml_as_string = dom.toprettyxml(indent = " ")
|
||||||
|
|
||||||
|
with open("D:\\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:
|
||||||
|
shutil.copyfileobj(f_in, f_out)
|
||||||
|
|
||||||
|
files = []
|
||||||
|
commands = []
|
||||||
|
gZipFile = "D:\\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")
|
||||||
|
|
||||||
def makeBERecord():
|
|
||||||
pass
|
|
Loading…
x
Reference in New Issue
Block a user