-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
38 lines (31 loc) · 1.14 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import logging
from urllib.parse import urljoin
import requests
from bs4 import BeautifulSoup
import time
from config import url, interval_time
logging.basicConfig(
format='%(asctime)s %(levelname)s:%(message)s',
level=logging.INFO)
def handle_found_appointments(num_found):
# you can add your own handler (e.g. sounds, telegram) here
print("Yeah! %d possible appointments" % num_found)
# This Character plays the default error sound on Ubuntu. I don't know if it works for Windows though
print("\a")
def crawl():
html = requests.get(url)
if(html.status_code != 200):
print("Website Error")
return
soup = BeautifulSoup(html.text, 'html.parser')
logging.info("Occupied: %d" % len(soup.find_all("td", { "class": "nichtbuchbar" })))
found = len(soup.find_all("td", { "class": "buchbar" }))
if found > 0:
logging.info("FOUND %d POSSIBLE APPOINTMENTS!" % found)
handle_found_appointments(found)
if url == "enter-url-here":
logging.error("You have to enter a URL (get from Bürgeramt 'Termin Berlinweit suchen')")
exit()
while True:
crawl()
time.sleep(interval_time)