-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
440 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,198 @@ | ||
{ | ||
"type": "FeatureCollection", | ||
"features": [ | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
7.7664756774902335, | ||
49.44435650387989 | ||
] | ||
}, | ||
"properties": { | ||
"name": "Kaiserslautern", | ||
"type": "city", | ||
"url": "https://www.kaiserslautern.de/live_tools/pls/pls.xml", | ||
"source": "https://www.kaiserslautern.de/live_tools/pls/pls.xml", | ||
"active_support": true | ||
} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"properties": { | ||
"name": "PH Lutrinastraße", | ||
"address": "Badstraße 3", | ||
"type": "Parkhaus", | ||
"total": 67 | ||
}, | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
7.772792279720306, | ||
49.44166030571838 | ||
] | ||
} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
7.77245968580246, | ||
49.44463553274022 | ||
] | ||
}, | ||
"properties": { | ||
"name": "PH Stiftsplatz", | ||
"address": "Stiftsplatz", | ||
"type": "Parkhaus", | ||
"total": 100 | ||
} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
7.763890027999877, | ||
49.44643523073805 | ||
] | ||
}, | ||
"properties": { | ||
"name": "PH Meuthstraße Besucher", | ||
"address": "Meuthstraße", | ||
"type": "Parkplatz", | ||
"total": 79 | ||
} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
7.764085829257964, | ||
49.44693746024965 | ||
] | ||
}, | ||
"properties": { | ||
"name": "PH Meuthstraße Angestellte", | ||
"address": "Meuthstraße", | ||
"type": "Parkplatz", | ||
"total": 249 | ||
} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
7.769994735717773, | ||
49.446316648019256 | ||
] | ||
}, | ||
"properties": { | ||
"name": "PH Pfalztheater", | ||
"address": "Martin-Luther-Straße", | ||
"type": "Parkhaus", | ||
"total": 178 | ||
} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
7.7724650502204895, | ||
49.446974080950305 | ||
] | ||
}, | ||
"properties": { | ||
"name": "PH Altstadt", | ||
"address": "Rittersberg 2", | ||
"type": "Parkhaus", | ||
"total": 258 | ||
} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
7.768429666757583, | ||
49.444547464427664 | ||
] | ||
}, | ||
"properties": { | ||
"name": "PH Kreissparkasse", | ||
"address": "Am Altenhof 8", | ||
"type": "Parkhaus", | ||
"total": 162 | ||
} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
7.764659821987151, | ||
49.443631021411605 | ||
] | ||
}, | ||
"properties": { | ||
"name": "PH K in Lautern", | ||
"address": "Fackelrondell 1", | ||
"type": "Parkhaus", | ||
"total": 460 | ||
} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
7.766937017440797, | ||
49.442239320669785 | ||
] | ||
}, | ||
"properties": { | ||
"name": "PH Central", | ||
"address": "Rosenstraße 12", | ||
"type": "Parkhaus", | ||
"total": 70 | ||
} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
7.767012119293212, | ||
49.44309736639787 | ||
] | ||
}, | ||
"properties": { | ||
"name": "PH City", | ||
"address": "Löwenstraße 5", | ||
"type": "Parkhaus", | ||
"total": 240 | ||
} | ||
}, | ||
{ | ||
"type": "Feature", | ||
"geometry": { | ||
"type": "Point", | ||
"coordinates": [ | ||
7.770386338233947, | ||
49.43580175486678 | ||
] | ||
}, | ||
"properties": { | ||
"name": "PH Hauptbahnhof", | ||
"address": "Zollamtstraße 6", | ||
"type": "Parkhaus", | ||
"total": 259 | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from datetime import datetime | ||
|
||
from bs4 import BeautifulSoup | ||
|
||
from park_api.geodata import GeoData | ||
from park_api.util import utc_now | ||
|
||
# This loads the geodata for this city if <city>.geojson exists in the same directory as this file. | ||
# No need to remove this if there's no geodata (yet), everything will still work. | ||
geodata = GeoData(__file__) | ||
|
||
|
||
# This function is called by the scraper and given the data of the page specified as source in geojson above. | ||
# It's supposed to return a dictionary containing everything the current spec expects. Tests will fail if it doesn't ;) | ||
|
||
def parse_html(xml): | ||
soup = BeautifulSoup(xml, "html.parser") | ||
|
||
# last_updated is the date when the data on the page was last updated, it should be listed on most pages | ||
|
||
try: | ||
last_updated = soup.select("zeitstempel")[0].text | ||
except KeyError: | ||
last_updated = utc_now() | ||
|
||
data = { | ||
# convert_date is a utility function you can use to turn this date into the correct string format | ||
"last_updated": datetime.strptime(last_updated[0:16], "%d.%m.%Y %H:%M").isoformat(), | ||
# URL for the page where the scraper can gather the data | ||
"lots": [] | ||
} | ||
|
||
for ph in soup.find_all("parkhaus"): | ||
lot_name = ph.find("name").text | ||
lot_actual = int(ph.find("aktuell").text) | ||
lot_total = int(ph.find("gesamt").text) | ||
lot_free = lot_total - lot_actual | ||
|
||
# please be careful about the state only being allowed to contain either open, closed or nodata | ||
# should the page list other states, please map these into the three listed possibilities | ||
# translate german state to english | ||
stateGerman = ph.find("status").text | ||
if stateGerman == ("Offen"): | ||
state = "open" | ||
elif stateGerman == ("Geschlossen"): | ||
state = "closed" | ||
else: | ||
state = "nodata" | ||
|
||
lot = geodata.lot(lot_name) | ||
data["lots"].append({ | ||
"name": lot.name, | ||
"free": lot_free, | ||
"total": lot_total, | ||
"address": lot.address, | ||
"coords": lot.coords, | ||
"state": state, | ||
"lot_type": lot.type, | ||
"id": lot.id, | ||
"forecast": False, | ||
}) | ||
|
||
return data |
Oops, something went wrong.