Skip to content

Commit

Permalink
quickfix aalborg
Browse files Browse the repository at this point in the history
ref #212
  • Loading branch information
jklmnn committed Sep 6, 2019
1 parent 9a75db0 commit 706ad02
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 417 deletions.
4 changes: 2 additions & 2 deletions park_api/cities/Aalborg.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
"name": "Aalborg",
"type": "city",
"url": "http://www.aalborgcity.dk/live-parkering.aspx",
"source": "http://plcinfo.mintrafik.dk/gadget/getParkPlacesAreaMarkers.aspx",
"active_support": false,
"source": "http://plcinfo.mintrafik.dk/",
"active_support": false,
"attribution":{
"contributor":"Manuel R. Ciosici",
"url":"http://www.aalborgcity.dk/live-parkering.aspx",
Expand Down
52 changes: 19 additions & 33 deletions park_api/cities/Aalborg.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@


def parse_html(text_content):
# the original JSON is invalid, let's fix it
p = re.compile(r'([^"]|\s)([a-zA-Z]+)\s?(:)')
text_content = text_content.replace("'", "\"")
text_content = re.sub(p, r'\1"\2"\3', text_content)
data_as_json = json.loads(text_content)

# the source doesn't publish the update time, so we assume present
last_updated = datetime.now().strftime("%Y/%m/%d %H:%M:%S")

elems = text_content.split("\r\n\r\n")

data = {
"last_updated": convert_date(last_updated, "%Y/%m/%d %H:%M:%S"),
"last_updated": convert_date(elems[0], "%d-%m-%Y %H:%M:%S "),
"lots": []
}

Expand All @@ -27,29 +22,20 @@ def parse_html(text_content):
0: "closed"
}

for record in data_as_json["parkPlacesAreaMarkers"]:
lot_name = record["Name"]
free = int(record["FreeCount"])
total = int(record["MaxCount"])

# the JSON file contains parking lots for which counting does work, let's ignore them
if total > 0:
latitude = record["Latitude"]
longitude = record["Longitude"]
state_key = int(record["IsOpen"])
state = state_mappings[state_key]

lot = geodata.lot(lot_name)
data["lots"].append({
"name": lot_name,
"free": free,
"total": total,
"address": lot.address,
"coords": lot.coords,
"state": state,
"lot_type": lot.type,
"id": lot.id,
"forecast": False,
})
for elem in elems[1:]:
e = {"name": elem.split("\r\n")[0].split("=")[1],
"free": int(elem.split("\r\n")[1].split("=")[1])}
lot = geodata.lot(e["name"])
data["lots"].append({
"name": e["name"],
"free": e["free"],
"total": lot.total,
"address": lot.address,
"coords": lot.coords,
"state": "unknown",
"lot_type": lot.type,
"id": lot.id,
"forecast": False,
})

return data
46 changes: 46 additions & 0 deletions tests/fixtures/aalborg.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
06-09-2019 13:17:10

PLADS=Østre Havn
ANTAL=404

PLADS=Sømandshjemmet
ANTAL=46

PLADS=Sauers Plads
ANTAL=0

PLADS=Salling
ANTAL=98

PLADS=Plaza P-Hus Syd
ANTAL=15

PLADS=Plaza P-Hus Nord
ANTAL=11

PLADS=Palads
ANTAL=219

PLADS=Musikkens Hus
ANTAL=4

PLADS=Kongrescenter
ANTAL=306

PLADS=Kennedy Arkaden
ANTAL=217

PLADS=Gåsepigen
ANTAL=1

PLADS=Føtex
ANTAL=80

PLADS=Friis
ANTAL=183

PLADS=C W Obel
ANTAL=306

PLADS=Budolfi Plads
ANTAL=0
Loading

0 comments on commit 706ad02

Please sign in to comment.