Ready for testing
This commit is contained in:
parent
215faa4bab
commit
27bdce5ce9
10
dockerfile
Normal file
10
dockerfile
Normal file
@ -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" ]
|
||||
52
main.py
Normal file
52
main.py
Normal file
@ -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('<span>','').replace('</span>', '').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)
|
||||
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
influxdb
|
||||
bs4
|
||||
Loading…
Reference in New Issue
Block a user