Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Robustness fixes #12

Merged
merged 5 commits into from
Nov 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions parking_lots.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"capacity": 97,
"type": "Parkhaus",
"url": "https://stadtwerke.herrenberg.de/oepnv-parken/parken/sicher-und-zentral-parken/parkhaeuser-und-parkgebuehren/altstadtgarage/",
"fee": "Mo-Fr 08:00-20:00; Sa 08:00-14:00; PH off"
"fee_hours": "Mo-Fr 08:00-20:00; Sa 08:00-14:00; PH off"
}
},
{
Expand All @@ -51,7 +51,7 @@
"capacity": 24,
"type": "Parkplatz",
"url": "https://www.herrenberg.de/de/Stadtleben/Erlebnis-Herrenberg/Service/Parkplaetze/Parkplatz?view=publish&item=parkingLocation&id=1002",
"openingHours": "Mo - Su 00:00-24:00; PH 00:00-24:00"
"opening_hours": "Mo - Su 00:00-24:00; PH 00:00-24:00"
}
},

Expand All @@ -70,7 +70,7 @@
"capacity": 39,
"type": "Parkplatz",
"url": "https://www.herrenberg.de/de/Stadtleben/Erlebnis-Herrenberg/Service/Parkplaetze/Parkplatz?view=publish&item=parkingLocation&id=1002",
"openingHours": "Mo,We,Th,Fr,Su 00:00-24:00; Tu,Sa 00:00-02:00, 14:30-24:00; PH 00:00-24:00"
"opening_hours": "Mo,We,Th,Fr,Su 00:00-24:00; Tu,Sa 00:00-02:00, 14:30-24:00; PH 00:00-24:00"
}
},
{
Expand All @@ -87,7 +87,7 @@
"capacity": 47,
"type": "Parkplatz",
"url": "https://stadtwerke.herrenberg.de/oepnv-parken/parken/sicher-und-zentral-parken/parkhaeuser-und-parkgebuehren/kurzzeitparkplaetze-bahnhofstrasse/",
"fee": "Mo-Fr 08:00-20:00; Sa 08:00-14:00; PH off"
"fee_hours": "Mo-Fr 08:00-20:00; Sa 08:00-14:00; PH off"
}
},
{
Expand Down Expand Up @@ -121,8 +121,8 @@
"capacity": 90,
"type": "Tiefgarage",
"url": "https://stadtwerke.herrenberg.de/oepnv-parken/parken/sicher-und-zentral-parken/parkhaeuser-und-parkgebuehren/bronntor-tiefgarage/",
"fee": "Mo-Fr 08:00-20:00; Sa 08:00-14:00; PH off",
"openingHours": "Mo-Fr 07:30-22:00; Sa 07:30-18:00; PH off"
"fee_hours": "Mo-Fr 08:00-20:00; Sa 08:00-14:00; PH off",
"opening_hours": "Mo-Fr 07:30-22:00; Sa 07:30-18:00; PH off"
}
},
{
Expand Down Expand Up @@ -207,7 +207,7 @@
"capacity": 398,
"type": "Park-Ride",
"url": "https://stadtwerke.herrenberg.de/oepnv-parken/parken/sicher-und-zentral-parken/parkhaeuser-und-parkgebuehren/p-r-parkhaus/",
"fee": "Mo-Fr 08:00-20:00; Sa 08:00-14:00; PH off"
"fee_hours": "Mo-Fr 08:00-20:00; Sa 08:00-14:00; PH off"
}
},
{
Expand Down
31 changes: 22 additions & 9 deletions thingsboard-to-parkapi
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ def allowed_gai_family():
urllib3_cn.allowed_gai_family = allowed_gai_family

parser = ArgumentParser()
parser.add_argument("-o", "--output", help="write output to FILE")
parser.add_argument("-g", "--geojson", help="the static geojson input file")
parser.add_argument("-o", "--output", help="write output to FILE", default="parkapi.json")
parser.add_argument("-g", "--geojson", help="the static geojson input file", default="parking_lots.geojson")
args = parser.parse_args()

base_url = "https://portal.mhascaro.com/api"
Expand All @@ -47,7 +47,7 @@ list_url = f"{base_url}/entityGroup/3c521c80-53bd-11ea-aa10-3316385c1cc2/entitie

response = requests.get(list_url, headers=auth_headers)

parking_lots = response.json()["data"]
parking_lots = response.json().get("data", [])

def get_attribute(items, name):
for i in items:
Expand Down Expand Up @@ -118,16 +118,19 @@ def fetch_static_lots():
"address": props["name"],
"name": props["name"],
"forecast": False,
"state": "nodata",
"state": props.get("state", "nodata"),
"lat": float(coords[1]),
"lon": float(coords[0]),
# deprecated: parkapi standard currently doesn't use nested propeties...
"coords" : {
"lat": float(coords[1]),
"lng": float(coords[0])
},
"total": props["capacity"],
"free": props.get("free"),
"url": props.get("url"),
"paid_hours": props.get("paidHours"),
"opening_hours": props.get("openingHours")
"fee_hours": props.get("fee_hours"),
"opening_hours": props.get("opening_hours")
}
res.append(clean_nones(l))

Expand All @@ -142,9 +145,19 @@ print(f"Fetched {len(static_lots)} static parking lots")
def merge_data(dynamic, static):
for lot in static:
id = lot.get("id")
if(id != None):
dynamic_lot = [x for x in dynamic if x["id"] == id][0]
lot["free"] = dynamic_lot["free"]
if id != None and lot["state"] != "closed":
dynamic_lots = [x for x in dynamic if x["id"] == id]
if len(dynamic_lots) > 0:
dynamic_lot = dynamic_lots[0]

lot["free"] = dynamic_lot["free"]
if lot["free"] <= 0:
lot["status"] == "full"
elif lot["free"] <= 5 or lot["free"]/lot["total"] < 0.05:
lot["status"] == "few"
else:
lot["status"] == "many"


return static

Expand Down