From 27bdce5ce98a47f6e4e80b0fc05c44daeb0c9e7d Mon Sep 17 00:00:00 2001 From: Sean Corrigan Date: Fri, 14 Jan 2022 00:55:20 -0500 Subject: [PATCH] Ready for testing --- dockerfile | 10 ++++++++++ main.py | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 2 ++ 3 files changed, 64 insertions(+) create mode 100644 dockerfile create mode 100644 main.py create mode 100644 requirements.txt diff --git a/dockerfile b/dockerfile new file mode 100644 index 0000000..21ac735 --- /dev/null +++ b/dockerfile @@ -0,0 +1,10 @@ +# set base image (host OS) +FROM python:3.8 +# copy the dependencies file to the working directory +COPY requirements.txt . +# install dependencies +RUN pip install -r requirements.txt +# copy the content of the local src directory to the working directory +COPY main.py . +# command to run on container start +CMD [ "python", "./main.py" ] diff --git a/main.py b/main.py new file mode 100644 index 0000000..dda8ef5 --- /dev/null +++ b/main.py @@ -0,0 +1,52 @@ +import requests +from bs4 import BeautifulSoup +from datetime import time + +from influxdb import InfluxDBClient + + + +def uploadInflux(data, host='10.0.5.51', port=8086): # Main upload + json_body = [ + { + "measurement": "liftdata", + "tags": { + 'resort': 'brimbacombe', + }, + "fields": { + 'trails-day' : int(data['trails-day']), + 'trails-night' :int(data['trails-night']), + 'open-parks' : int(data['open-parks']), + 'lift-day' : int(data['lift-day']), + 'lift-night' : int(data['lift-night']), + 'snowflake' : data['snowflake'], + } + } + ] + + client = InfluxDBClient(host, port, database = "telegraf") # Init connection to Influx Server + client.write_points(json_body) # Write Speedtest results + +def main(): + URL = "https://brimacombe.ca/snow-conditions-and-trails" + r = requests.get(URL) + soup = BeautifulSoup(r.content, 'html5lib') + table = soup.find_all('div', attrs = {'class':'condition-item'}) + + infodict = {} + + for item in table: + title = item.find('img')['src'].replace('/a/img/icon-', '').replace('.png', '') + value = str(item.find('span')).replace('','').replace('', '').strip() + infodict[title] = value + + # for item in infodict: + # print('{}: {}'.format(item, infodict[item])) + + uploadInflux(infodict) + # print(table) + +while True: + main() + print('DATA FETCHED AND UPLOADEDED') + time.sleep(10000) \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..34b8ccb --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +influxdb +bs4