-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLuebeck.py
More file actions
77 lines (62 loc) · 2.15 KB
/
Luebeck.py
File metadata and controls
77 lines (62 loc) · 2.15 KB
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
from bs4 import BeautifulSoup
from park_api.util import convert_date, get_most_lots_from_known_data
from park_api.geodata import GeoData
process_state_map = {
"": "open",
"Geöffnet": "open",
"Vorübergehend geschlossen.": "closed",
"Vorübergehend geschlossen": "closed",
"Geschlossen": "closed"
}
geodata = GeoData(__file__)
def parse_html(html):
soup = BeautifulSoup(html, "html.parser")
date_field = soup.find("tr").find("strong").text
last_updated = convert_date(date_field, "Stand: %d.%m.%Y, %H:%M Uhr")
data = {
"last_updated": last_updated,
"lots": []
}
rows = soup.find_all("tr")
rows = rows[1:]
region_header = ""
for row in rows:
if len(row.find_all("th")) > 0:
# This is a header row, save it for later
region_header = row.find("th", {"class": "head1"}).text
else:
if row.find("td").text == "Gesamt":
continue
# This is a parking lot row
raw_lot_data = row.find_all("td")
type_and_name = process_name(raw_lot_data[0].text)
if len(raw_lot_data) == 2:
total = get_most_lots_from_known_data("Lübeck",
type_and_name[1])
free = 0
state = process_state_map.get(raw_lot_data[1].text, "")
elif len(raw_lot_data) == 4:
total = int(raw_lot_data[1].text)
free = int(raw_lot_data[2].text)
state = "open"
lot = geodata.lot(type_and_name[1])
data["lots"].append({
"name": lot.name,
"lot_type": type_and_name[0],
"total": total,
"free": free,
"region": region_header,
"state": state,
"coords": lot.coords,
"id": lot.id,
"forecast": False
})
return data
def process_name(name):
lot_type = name[:2]
lot_name = name[3:]
type_mapping = {
"PP": "Parkplatz",
"PH": "Parkhaus",
}
return type_mapping.get(lot_type, ""), lot_name