Skip to content

Instantly share code, notes, and snippets.

@PaulSt
Last active June 7, 2021 16:21
Show Gist options
  • Save PaulSt/dc03619f67bc5b9c5d45160004b80b43 to your computer and use it in GitHub Desktop.
Save PaulSt/dc03619f67bc5b9c5d45160004b80b43 to your computer and use it in GitHub Desktop.
from urllib.request import urlopen
from bs4 import BeautifulSoup
import re
import pandas as pd
import time
import matplotlib.pyplot as plt,mpld3
import json
try:
df = pd.read_csv("/home/pi/boulder/can-i-boulder.csv",index_col='time')
except:
df = pd.DataFrame()
print("creating new df")
#boulderbar
url = "https://shop.boulderbar.net:8080/modules/bbext/CurrentCustomer.php"
page = urlopen(url)
html = page.read().decode("utf-8")
soup = BeautifulSoup(html, "html.parser")
text = soup.get_text().strip()
r = re.compile("([a-zA-Z]+)([0-9]+)")
data = [r.match(t.replace("über ","").strip("plätze ")).groups() for t in text.strip("frei").split("frei")]
#blockfabrik
url = "https://www.boulderado.de/boulderadoweb/gym-clientcounter/index.php?mode=get&token=eyJhbGciOiJIUzI1NiIsICJ0eXAiOiJKV1QifQ.eyJjdXN0b21lciI6IkJsb2NrZmFicmlrV2llbiJ9.yymz1Eg_-jX28iMdaq1aGVb0iD4-29uWVkuxZd7a_9U&raw=1"
page = urlopen(url)
dict = json.load(page)
value = dict["maxcount"]-dict["counter"]
data.append(("Blockfabrik", value))
new_row=pd.DataFrame([[d[1] for d in data]],columns=[d[0] for d in data], index=[pd.Timestamp.now()])
df = pd.concat([df,new_row], ignore_index=False)
df=df.astype(float)
df.index = pd.to_datetime(df.index)
fig = df.plot()
# plt.show()
mpld3.save_html(fig.get_figure(),"/home/pi/boulder/can-i-boulder.html")
df.to_csv("/home/pi/boulder/can-i-boulder.csv",index_label='time')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment