From 7e074949935e1641142f6e6aa1cc1f03b0119871 Mon Sep 17 00:00:00 2001 From: April Date: Sat, 8 Oct 2022 16:41:05 -0700 Subject: [PATCH] Add the rest of Floppa's i2 scripts --- py2Lib/MachineProductCfg.py | 1 + recordGenerators/CurrentConditions.py | 7 --- recordGenerators/CurrentObservations.py | 70 +++++++++++++++++++++++++ recordGenerators/DailyForecast.py | 68 ++++++++++++++++++++++++ recordGenerators/HourlyForecast.py | 68 ++++++++++++++++++++++++ 5 files changed, 207 insertions(+), 7 deletions(-) create mode 100644 py2Lib/MachineProductCfg.py delete mode 100644 recordGenerators/CurrentConditions.py create mode 100644 recordGenerators/CurrentObservations.py create mode 100644 recordGenerators/DailyForecast.py create mode 100644 recordGenerators/HourlyForecast.py diff --git a/py2Lib/MachineProductCfg.py b/py2Lib/MachineProductCfg.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/py2Lib/MachineProductCfg.py @@ -0,0 +1 @@ + diff --git a/recordGenerators/CurrentConditions.py b/recordGenerators/CurrentConditions.py deleted file mode 100644 index 30a8220..0000000 --- a/recordGenerators/CurrentConditions.py +++ /dev/null @@ -1,7 +0,0 @@ -import requests - -apiKey = '' - - -def getCurrentConditions(locId): - pass \ No newline at end of file diff --git a/recordGenerators/CurrentObservations.py b/recordGenerators/CurrentObservations.py new file mode 100644 index 0000000..f04b80a --- /dev/null +++ b/recordGenerators/CurrentObservations.py @@ -0,0 +1,70 @@ +import requests +import bit +import gzip +import uuid +import os +import shutil +import xml.dom.minidom + +tecciId = ['T72462058'] +zipCodes = ['81242'] + + +apiKey = '21d8a80b3d6b444998a80b3d6b1449d3' + +def getData(tecci, zipCode): + fetchUrl = 'https://api.weather.com/v1/location/' + zipCode + ':4:US/observations/current.xml?language=en-US&units=e&apiKey=' + apiKey + + #Fetch data + + response = requests.get(fetchUrl) + + data = response.text + + newData = data[67:-30] + + print('Gathering data for location id ' + tecci) + #Write to .i2m file + i2Doc = '' + '' + newData + '' + str(tecci) + '' + + + f = open("D:\\CurrentObservations.i2m", "a") + f.write(i2Doc) + f.close() + +header = '' +footer = '' + +with open("D:\\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: + end.write(footer) + +dom = xml.dom.minidom.parse("D:\\CurrentObservations.i2m") +pretty_xml_as_string = dom.toprettyxml(indent = " ") + +with open("D:\\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: + shutil.copyfileobj(f_in, f_out) + +gZipFile = "D:\\CurrentObservations.gz" + +files.append(gZipFile) +command = commands.append('') +numFiles = len(files) + +bit.sendFile(files, commands, numFiles, 0) + +os.remove("D:\\CurrentObservations.i2m") +os.remove("D:\\CurrentObservations.gz") diff --git a/recordGenerators/DailyForecast.py b/recordGenerators/DailyForecast.py new file mode 100644 index 0000000..b39c839 --- /dev/null +++ b/recordGenerators/DailyForecast.py @@ -0,0 +1,68 @@ +import requests +import bit +import gzip +import uuid +import os +import shutil +import xml.dom.minidom + +tecciId = ['72462058'] +zipCodes = ['81242'] + +apiKey = '21d8a80b3d6b444998a80b3d6b1449d3' + +def getData(tecci, zipCode): + fetchUrl = 'https://api.weather.com/v1/location/' + zipCode + ':4:US/forecast/daily/7day.xml?language=en-US&units=e&apiKey=' + apiKey + + #Fetch data + + response = requests.get(fetchUrl) + + data = response.text + + newData = data[61:-24] + + print('Gathering data for location id ' + tecci) + #Write to .i2m file + i2Doc = '' + '' + newData + '' + str(tecci) + '' + + f = open("D:\\DailyForecast.i2m", "a") + f.write(i2Doc) + f.close() + +header = '' +footer = '' + +with open("D:\\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: + end.write(footer) + + +dom = xml.dom.minidom.parse("D:\\DailyForecast.i2m") +pretty_xml_as_string = dom.toprettyxml(indent = " ") + +with open("D:\\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: + shutil.copyfileobj(f_in, f_out) + +gZipFile = "D:\\DailyForecast.gz" + +files.append(gZipFile) +command = commands.append('') +numFiles = len(files) + +bit.sendFile(files, commands, numFiles, 0) + +os.remove("D:\\DailyForecast.i2m") +os.remove("D:\\DailyForecast.gz") \ No newline at end of file diff --git a/recordGenerators/HourlyForecast.py b/recordGenerators/HourlyForecast.py new file mode 100644 index 0000000..d54c9c8 --- /dev/null +++ b/recordGenerators/HourlyForecast.py @@ -0,0 +1,68 @@ +import requests +import bit +import gzip +import uuid +import os +import shutil +import xml.dom.minidom + +tecciId = ['72462058'] +zipCodes = ['81242'] + +apiKey = '21d8a80b3d6b444998a80b3d6b1449d3' + +def getData(tecci, zipCode): + fetchUrl = 'https://api.weather.com/v1/location/' + zipCode + ':4:US/forecast/hourly/360hour.xml?language=en-US&units=e&apiKey=' + apiKey + + #Fetch data + + response = requests.get(fetchUrl) + + data = response.text + + newData = data[48:-11] + + print('Gathering data for location id ' + tecci) + #Write to .i2m file + i2Doc = '' + '' + newData + '' + str(tecci) + '' + + f = open("D:\\HourlyForecast.i2m", "a") + f.write(i2Doc) + f.close() + +header = '' +footer = '' + +with open("D:\\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: + end.write(footer) + + +dom = xml.dom.minidom.parse("D:\\HourlyForecast.i2m") +pretty_xml_as_string = dom.toprettyxml(indent = " ") + +with open("D:\\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: + shutil.copyfileobj(f_in, f_out) + +gZipFile = "D:\\HourlyForecast.gz" + +files.append(gZipFile) +command = commands.append('') +numFiles = len(files) + +bit.sendFile(files, commands, numFiles, 0) + +os.remove("D:\\HourlyForecast.i2m") +os.remove("D:\\HourlyForecast.gz") \ No newline at end of file