mirror of
https://github.com/mewtek/i2ME-Legacy.git
synced 2025-05-12 09:20:23 -05:00
WateringNeeds, Aches & Pains, and Mosquito Activity records
This commit is contained in:
parent
28d00ef20c
commit
910d692f0d
76
recordGenerators/AchesAndPains.py
Normal file
76
recordGenerators/AchesAndPains.py
Normal file
@ -0,0 +1,76 @@
|
||||
import shutil
|
||||
import requests
|
||||
import logging,coloredlogs
|
||||
from py2Lib import bit
|
||||
import Util.MachineProductCfg as MPC
|
||||
import records.LFRecord as LFR
|
||||
import gzip
|
||||
from os import remove
|
||||
import xml.dom.minidom
|
||||
|
||||
l = logging.getLogger(__name__)
|
||||
coloredlogs.install()
|
||||
|
||||
geocodes = []
|
||||
coopIds = []
|
||||
|
||||
for i in MPC.getPrimaryLocations():
|
||||
coopIds.append(LFR.getCoopId(i))
|
||||
geocodes.append(LFR.getLatLong(i).replace('/', ','))
|
||||
|
||||
apiKey = "21d8a80b3d6b444998a80b3d6b1449d3"
|
||||
|
||||
def getData(coopId, geocode):
|
||||
fetchUrl = f"https://api.weather.com/v2/indices/achePain/daypart/7day?geocode={geocode}&language=en-US&format=xml&apiKey={apiKey}"
|
||||
|
||||
res = requests.get(fetchUrl)
|
||||
|
||||
if res.status_code != 200:
|
||||
l.error("DO NOT REPORT THE ERROR BELOW")
|
||||
l.error(f"Failed to write AchesAndPains record -- Status code {res.status_code}")
|
||||
return
|
||||
|
||||
data = res.text
|
||||
newData = data[63:-26]
|
||||
|
||||
i2Doc = f'\n <AchesAndPains id="000000000" locationKey="{coopId}" isWxScan="0">\n {newData}\n <clientKey>{coopId}</clientKey>\n </AchesAndPains>'
|
||||
|
||||
f = open('./.temp/AchesAndPains.i2m', 'a')
|
||||
f.write(i2Doc)
|
||||
f.close()
|
||||
|
||||
def makeRecord():
|
||||
l.info("Writing AchesAndPains record.")
|
||||
|
||||
header = '<Data type="AchesAndPains">'
|
||||
footer = '</Data>'
|
||||
|
||||
with open('./.temp/AchesAndPains.i2m', 'a') as doc:
|
||||
doc.write(header)
|
||||
|
||||
for (x, y) in zip(coopIds, geocodes):
|
||||
getData(x,y)
|
||||
|
||||
with open('./.temp/AchesAndPains.i2m', 'a') as end:
|
||||
end.write(footer)
|
||||
|
||||
dom = xml.dom.minidom.parse('./.temp/AchesAndPains.i2m')
|
||||
xmlPretty = dom.toprettyxml(indent= " ")
|
||||
|
||||
with open('./.temp/AchesAndPains.i2m', 'w') as g:
|
||||
g.write(xmlPretty[23:])
|
||||
g.close()
|
||||
|
||||
|
||||
# Compresss i2m to gzip
|
||||
with open ('./.temp/AchesAndPains.i2m', 'rb') as f_in:
|
||||
with gzip.open('./.temp/AchesAndPains.gz', 'wb') as f_out:
|
||||
shutil.copyfileobj(f_in, f_out)
|
||||
|
||||
file = "./.temp/AchesAndPains.gz"
|
||||
command = '<MSG><Exec workRequest="storeData(File={0},QGROUP=__AchesAndPains__,Feed=AchesAndPains)" /><GzipCompressedMsg fname="AchesAndPains" /></MSG>'
|
||||
|
||||
bit.sendFile([file], [command], 1, 0)
|
||||
|
||||
remove('./.temp/AchesAndPains.i2m')
|
||||
remove('./.temp/AchesAndPains.gz')
|
76
recordGenerators/MosquitoActivity.py
Normal file
76
recordGenerators/MosquitoActivity.py
Normal file
@ -0,0 +1,76 @@
|
||||
import shutil
|
||||
import requests
|
||||
import logging,coloredlogs
|
||||
from py2Lib import bit
|
||||
import Util.MachineProductCfg as MPC
|
||||
import records.LFRecord as LFR
|
||||
import gzip
|
||||
from os import remove
|
||||
import xml.dom.minidom
|
||||
|
||||
l = logging.getLogger(__name__)
|
||||
coloredlogs.install()
|
||||
|
||||
geocodes = []
|
||||
coopIds = []
|
||||
|
||||
for i in MPC.getPrimaryLocations():
|
||||
coopIds.append(LFR.getCoopId(i))
|
||||
geocodes.append(LFR.getLatLong(i).replace('/', ','))
|
||||
|
||||
apiKey = "21d8a80b3d6b444998a80b3d6b1449d3"
|
||||
|
||||
def getData(coopId, geocode):
|
||||
fetchUrl = f"https://api.weather.com/v2/indices/mosquito/daypart/7day?geocode={geocode}&language=en-US&format=xml&apiKey={apiKey}"
|
||||
|
||||
res = requests.get(fetchUrl)
|
||||
|
||||
if res.status_code != 200:
|
||||
l.error("DO NOT REPORT THE ERROR BELOW")
|
||||
l.error(f"Failed to write MosquitoActivity record -- Status code {res.status_code}")
|
||||
return
|
||||
|
||||
data = res.text
|
||||
newData = data[63:-26]
|
||||
|
||||
i2Doc = f'\n <MosquitoActivity id="000000000" locationKey="{coopId}" isWxScan="0">\n {newData}\n <clientKey>{coopId}</clientKey>\n </MosquitoActivity>'
|
||||
|
||||
f = open('./.temp/MosquitoActivity.i2m', 'a')
|
||||
f.write(i2Doc)
|
||||
f.close()
|
||||
|
||||
def makeRecord():
|
||||
l.info("Writing MosquitoActivity record.")
|
||||
|
||||
header = '<Data type="MosquitoActivity">'
|
||||
footer = '</Data>'
|
||||
|
||||
with open('./.temp/MosquitoActivity.i2m', 'a') as doc:
|
||||
doc.write(header)
|
||||
|
||||
for (x, y) in zip(coopIds, geocodes):
|
||||
getData(x,y)
|
||||
|
||||
with open('./.temp/MosquitoActivity.i2m', 'a') as end:
|
||||
end.write(footer)
|
||||
|
||||
dom = xml.dom.minidom.parse('./.temp/MosquitoActivity.i2m')
|
||||
xmlPretty = dom.toprettyxml(indent= " ")
|
||||
|
||||
with open('./.temp/MosquitoActivity.i2m', 'w') as g:
|
||||
g.write(xmlPretty[23:])
|
||||
g.close()
|
||||
|
||||
|
||||
# Compresss i2m to gzip
|
||||
with open ('./.temp/MosquitoActivity.i2m', 'rb') as f_in:
|
||||
with gzip.open('./.temp/MosquitoActivity.gz', 'wb') as f_out:
|
||||
shutil.copyfileobj(f_in, f_out)
|
||||
|
||||
file = "./.temp/MosquitoActivity.gz"
|
||||
command = '<MSG><Exec workRequest="storeData(File={0},QGROUP=__MosquitoActivity__,Feed=MosquitoActivity)" /><GzipCompressedMsg fname="MosquitoActivity" /></MSG>'
|
||||
|
||||
bit.sendFile([file], [command], 1, 0)
|
||||
|
||||
remove('./.temp/MosquitoActivity.i2m')
|
||||
remove('./.temp/MosquitoActivity.gz')
|
76
recordGenerators/WateringNeeds.py
Normal file
76
recordGenerators/WateringNeeds.py
Normal file
@ -0,0 +1,76 @@
|
||||
import shutil
|
||||
import requests
|
||||
import logging,coloredlogs
|
||||
from py2Lib import bit
|
||||
import Util.MachineProductCfg as MPC
|
||||
import records.LFRecord as LFR
|
||||
import gzip
|
||||
from os import remove
|
||||
import xml.dom.minidom
|
||||
|
||||
l = logging.getLogger(__name__)
|
||||
coloredlogs.install()
|
||||
|
||||
geocodes = []
|
||||
coopIds = []
|
||||
|
||||
for i in MPC.getPrimaryLocations():
|
||||
coopIds.append(LFR.getCoopId(i))
|
||||
geocodes.append(LFR.getLatLong(i).replace('/', ','))
|
||||
|
||||
apiKey = "21d8a80b3d6b444998a80b3d6b1449d3"
|
||||
|
||||
def getData(coopId, geocode):
|
||||
fetchUrl = f"https://api.weather.com/v2/indices/wateringNeeds/daypart/7day?geocode={geocode}&language=en-US&format=xml&apiKey={apiKey}"
|
||||
|
||||
res = requests.get(fetchUrl)
|
||||
|
||||
if res.status_code != 200:
|
||||
l.error("DO NOT REPORT THE ERROR BELOW")
|
||||
l.error(f"Failed to write WateringNeeds record -- Status code {res.status_code}")
|
||||
return
|
||||
|
||||
data = res.text
|
||||
newData = data[63:-26]
|
||||
|
||||
i2Doc = f'\n <WateringNeeds id="000000000" locationKey="{coopId}" isWxScan="0">\n {newData}\n <clientKey>{coopId}</clientKey>\n </WateringNeeds>'
|
||||
|
||||
f = open('./.temp/WateringNeeds.i2m', 'a')
|
||||
f.write(i2Doc)
|
||||
f.close()
|
||||
|
||||
def makeRecord():
|
||||
l.info("Writing WateringNeeds record.")
|
||||
|
||||
header = '<Data type="WateringNeeds">'
|
||||
footer = '</Data>'
|
||||
|
||||
with open('./.temp/WateringNeeds.i2m', 'a') as doc:
|
||||
doc.write(header)
|
||||
|
||||
for (x, y) in zip(coopIds, geocodes):
|
||||
getData(x,y)
|
||||
|
||||
with open('./.temp/WateringNeeds.i2m', 'a') as end:
|
||||
end.write(footer)
|
||||
|
||||
dom = xml.dom.minidom.parse('./.temp/WateringNeeds.i2m')
|
||||
xmlPretty = dom.toprettyxml(indent= " ")
|
||||
|
||||
with open('./.temp/WateringNeeds.i2m', 'w') as g:
|
||||
g.write(xmlPretty[23:])
|
||||
g.close()
|
||||
|
||||
|
||||
# Compresss i2m to gzip
|
||||
with open ('./.temp/WateringNeeds.i2m', 'rb') as f_in:
|
||||
with gzip.open('./.temp/WateringNeeds.gz', 'wb') as f_out:
|
||||
shutil.copyfileobj(f_in, f_out)
|
||||
|
||||
file = "./.temp/WateringNeeds.gz"
|
||||
command = '<MSG><Exec workRequest="storeData(File={0},QGROUP=__WateringNeeds__,Feed=WateringNeeds)" /><GzipCompressedMsg fname="WateringNeeds" /></MSG>'
|
||||
|
||||
bit.sendFile([file], [command], 1, 0)
|
||||
|
||||
remove('./.temp/WateringNeeds.i2m')
|
||||
remove('./.temp/WateringNeeds.gz')
|
Loading…
x
Reference in New Issue
Block a user