Skip to content

Instantly share code, notes, and snippets.

@tomkooij
Last active May 13, 2021 12:43
Show Gist options
  • Save tomkooij/91111dca2e3fcff8e71fca3eccce8a17 to your computer and use it in GitHub Desktop.
Save tomkooij/91111dca2e3fcff8e71fca3eccce8a17 to your computer and use it in GitHub Desktop.
Poll prullenvaccin
MAILTO=vaccin@no.net
# check elke 5 minuten. Er is output als er vaccins zijn. Die output wordt gemaild door cron
*/5 * * * * /home/tom/Miniconda3/env/py38/bin/python poll_vaccin.py
# coding: utf-8
from bs4 import BeautifulSoup
import requests
import re
url = "https://www.prullenbakvaccin.nl/"
posturl = "https://www.prullenbakvaccin.nl#location-selector"
def poll_site(location="1000"):
"""poll site for location and return list of locations"""
# TODO: Dit hoeft niet, want je kunt gewoon https://www.prullenbakvaccin.nl/gouda gebruiken
client = requests.session()
r = client.get(url)
soup = BeautifulSoup(r.text, 'html.parser')
token = soup.form.input['value']
data = {"_token": token, "location": location}
r = client.post(posturl, data)
soup = BeautifulSoup(r.text, 'html.parser')
return soup
def parse_priklocatie(s):
"""
Locatie #95 (17.99 km) Heeft geen vaccins
return id, dist (hele km)
"""
m = re.match(r".*#(\d+).*\((\d+).\d+ km\)", s)
if m:
id, dist = map(int, m.groups())
return id, dist
## voor debuggen zonder de hele tijd de site te pollen
soup = poll_site("gouda")
priklocaties = soup.find_all("div", {"class": "card-body"})
for priklocatie in priklocaties:
priklocatie = priklocatie.text.replace('\n', ' ')
if "Niet bellen" in priklocatie:
print(priklocatie)
id, dist = parse_priklocatie(priklocatie)
if dist < 5:
print('Vaccin beschikbaar binnen fietsafstand!!!')
print(priklocatie)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment