-
Notifications
You must be signed in to change notification settings - Fork 1
/
immervoll.py
104 lines (86 loc) · 3.68 KB
/
immervoll.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import re
from datetime import datetime
from typing import Tuple
import requests
from bs4 import BeautifulSoup
from event import DanceEvent
# Parses dates in the format: `Samstag, 21.01.2023 19:30 - 22:15 Uhr`
# which is quite common on the page.
def parse_datetimes(text: str) -> Tuple[datetime, datetime]:
date_text, start_text, end_text = re.search(
", ([0-9\\.]+) ([0-9:]+) - ([0-9:]+) Uhr", text
).groups()
day = datetime.strptime(date_text, "%d.%m.%Y")
start_hour = int(start_text.split(":")[0])
start_min = int(start_text.split(":")[1])
end_hour = int(end_text.split(":")[0])
end_min = int(end_text.split(":")[1])
return (
day.replace(hour=start_hour, minute=start_min),
day.replace(hour=end_hour, minute=end_min),
)
def download_immervoll() -> list[DanceEvent]:
response = requests.get("https://www.tanzschule-immervoll.at/events/", timeout=10)
response.raise_for_status()
soup = BeautifulSoup(response.text, features="html.parser")
table_elements = soup.find_all("table")
# Parse the events
events = []
events_table = table_elements[0]
for row in events_table.find_all("tr"):
# Check via the image if that is the right location (and yes this code
# hurts me as much as it does you)
if "standort_ac" in row.find("img")["src"]:
# Auhof is technically in Vienna but it is a pain to get there so
# no we won't list it on our page.
continue
info_td = row.find_all("td")[1]
starts_at, ends_at = parse_datetimes(info_td.text)
text: str = row.find("div").text
name, description = text.split("|", maxsplit=1)
name = " ".join(
map(lambda s: s.capitalize(), name.strip().replace("-", " ").split(" "))
)
description = description.replace("|", "\n").strip()
events.append(
DanceEvent(
starts_at=starts_at,
ends_at=ends_at,
name=name,
price_euro_cent=None,
description=description,
dancing_school="Immervoll",
website="https://www.tanzschule-immervoll.at/events/",
)
)
# Parse perfections
perfection_table = table_elements[2]
for row in perfection_table.find_all("tr"):
# Check via the image if that is the right location (and yes this code
# hurts me as much as it does you)
if "standort_ac" in row.find("img")["src"]:
# Auhof is technically in Vienna but it is a pain to get there so
# no we won't list it on our page.
continue
starts_at, ends_at = parse_datetimes(row.text.strip())
match starts_at.weekday():
case 1:
# Tuesday it's 15€ per couple
price = 1500 // 2
case 5:
# Saturday it's 17€ per couple
price = 1700 // 2
case _:
price = None
events.append(
DanceEvent(
starts_at=starts_at,
ends_at=ends_at,
name="Perfektion",
price_euro_cent=price,
description="Altgasse 6, 1130 Wien\nKeine Voranmeldung notwendig. Teilnahme nur paarweise möglich.\nVerschiedene Tanz- und Übungsabende runden unser Kursangebot ab! Hier kommen Schüler aus allen Kursstufen zusammen und perfektionieren ihr erworbenes Können. Gesellige Abende in unseren Tanzschulen bieten den optimalen Ausklang eines arbeitsreichen Tages.",
dancing_school="Immervoll",
website="https://www.tanzschule-immervoll.at/events/",
)
)
return events