Skip to content

Instantly share code, notes, and snippets.

@oliveratgithub
Last active May 20, 2022 13:53
Show Gist options
  • Save oliveratgithub/e503268f66f34c795b556eca5e056bfb to your computer and use it in GitHub Desktop.
Save oliveratgithub/e503268f66f34c795b556eca5e056bfb to your computer and use it in GitHub Desktop.
Sauna Stats Grabber: Sauna - Seebad Enge (https://www.seebadenge.ch/wp/sauna)

Sauna Stats Grabber

Sauna - Seebad Enge

Pre-requisites

Python version

python3

Python dependencies

sudo apt-get install python3-bs4 or… pip3 install beautifulsoup4

Usage

Run stand-alone

python3 /path/to/saunastatsgrabber.py

Run as background process

nohup python3 /path/to/saunastatsgrabber.py > /path/to/saunastatsgrabber.log 2>$

Check running background processes

sudo ps -ef | grep python

#!/usr/bin/env python3
import sys
import os
import datetime
from bs4 import BeautifulSoup
webpage='https://www.seebadenge.ch/wp/sauna'
file_out = '/home/inex/SCRIPTS/saunastats/saunastats.txt'
data_container = 'ase_crowdmonitor'
repeat=300
def getFreiePlaetze():
now = datetime.datetime.now()
# Open file to append
sys.stdout = fs = open(file_out, "a")
# Fetch using curl
html_doc = os.popen('curl -sSL '+webpage).read()
if 'curl: (' in html_doc:
# On error
print(str(now)+html_doc)
else:
# Parse
try:
soup = BeautifulSoup(html_doc, 'html.parser')
fly = soup.find('div', class_='ase_crowdmonitor')
print(fly.contents[0])
except:
print(str(now)+': ase_crowdmonitor not found (website down?)')
finally:
pass
fs.close()
import threading
import time
import schedule
while True:
getFreiePlaetze()
time.sleep(repeat)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment