From 706ad0285a3adbcc679a606de1056cdbf0a8c365 Mon Sep 17 00:00:00 2001 From: Johannes Kliemann Date: Fri, 6 Sep 2019 13:15:36 +0200 Subject: [PATCH] quickfix aalborg ref #212 --- park_api/cities/Aalborg.geojson | 4 +- park_api/cities/Aalborg.py | 52 ++--- tests/fixtures/aalborg.html | 46 ++++ tests/fixtures/aalborg.json | 382 -------------------------------- 4 files changed, 67 insertions(+), 417 deletions(-) create mode 100644 tests/fixtures/aalborg.html delete mode 100644 tests/fixtures/aalborg.json diff --git a/park_api/cities/Aalborg.geojson b/park_api/cities/Aalborg.geojson index e8cd566..2bec118 100644 --- a/park_api/cities/Aalborg.geojson +++ b/park_api/cities/Aalborg.geojson @@ -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", diff --git a/park_api/cities/Aalborg.py b/park_api/cities/Aalborg.py index 2428a5c..0c29a0b 100644 --- a/park_api/cities/Aalborg.py +++ b/park_api/cities/Aalborg.py @@ -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": [] } @@ -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 diff --git a/tests/fixtures/aalborg.html b/tests/fixtures/aalborg.html new file mode 100644 index 0000000..8e57ea9 --- /dev/null +++ b/tests/fixtures/aalborg.html @@ -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 \ No newline at end of file diff --git a/tests/fixtures/aalborg.json b/tests/fixtures/aalborg.json deleted file mode 100644 index 6c18e19..0000000 --- a/tests/fixtures/aalborg.json +++ /dev/null @@ -1,382 +0,0 @@ -{ - parkPlacesAreaMarkers:[ - { - Name:'Østre Havn', - Status:'0', - IsPaymentActive:'0 ', - Description:'', - DescriptionPublic:'', - IsOpen:'1 ', - CountOfHandicapPlaces:'0', - CountOfChargingStations:'0', - OpeningTimeDescription:'', - PayPeriodDescription:'', - PriceDescription:'', - PriceFreePeriod:'0', - PricePerMinut:'0', - AccessStreet:'', - Mode:'1', - Longitude:'9.935964', - Latitude:'57.04818', - ClosedWeekDay:'0', - ClosedFrom:'00:00', - ClosedTo:'00:00', - PayPeriodWeekDay:'0', - PayPeriodFrom:'00:00', - PayPeriodTo:'00:00', - MaxCount:'0', - FreeCount:'0' - }, - { - Name:'Toldbodgade', - Status:'0', - IsPaymentActive:'0 ', - Description:'', - DescriptionPublic:'', - IsOpen:'1 ', - CountOfHandicapPlaces:'0', - CountOfChargingStations:'0', - OpeningTimeDescription:'', - PayPeriodDescription:'', - PriceDescription:'', - PriceFreePeriod:'0', - PricePerMinut:'0', - AccessStreet:'', - Mode:'1', - Longitude:'9.917886', - Latitude:'57.05214', - ClosedWeekDay:'0', - ClosedFrom:'00:00', - ClosedTo:'00:00', - PayPeriodWeekDay:'0', - PayPeriodFrom:'00:00', - PayPeriodTo:'00:00', - MaxCount:'0', - FreeCount:'0' - }, - { - Name:'Sømandshjemmet', - Status:'0', - IsPaymentActive:'0 ', - Description:'', - DescriptionPublic:'', - IsOpen:'1 ', - CountOfHandicapPlaces:'0', - CountOfChargingStations:'0', - OpeningTimeDescription:'', - PayPeriodDescription:'', - PriceDescription:'', - PriceFreePeriod:'0', - PricePerMinut:'0', - AccessStreet:'P Ud - Privat P (4), P Ind - Privat P (3), P Ind - Nyhavnsgade (1), P Ud - Nyhavnsgade (2), ', - Mode:'1', - Longitude:'9.93556', - Latitude:'57.04646', - ClosedWeekDay:'0', - ClosedFrom:'00:00', - ClosedTo:'00:00', - PayPeriodWeekDay:'0', - PayPeriodFrom:'00:00', - PayPeriodTo:'00:00', - MaxCount:'78', - FreeCount:'78' - }, - { - Name:'Sauers Plads', - Status:'1', - IsPaymentActive:'0 ', - Description:'', - DescriptionPublic:'', - IsOpen:'1 ', - CountOfHandicapPlaces:'0', - CountOfChargingStations:'0', - OpeningTimeDescription:'', - PayPeriodDescription:'', - PriceDescription:'', - PriceFreePeriod:'0', - PricePerMinut:'0', - AccessStreet:'P Ind - Toldstrupsgade vest (3), P Ud- Toldstrupsgade vest (4), P Ud - Toldstrupsgade øst (2), P Ind - Toldstrupsgade øst (1), ', - Mode:'1', - Longitude:'9.92745', - Latitude:'57.04419', - ClosedWeekDay:'0', - ClosedFrom:'00:00', - ClosedTo:'00:00', - PayPeriodWeekDay:'0', - PayPeriodFrom:'00:00', - PayPeriodTo:'00:00', - MaxCount:'360', - FreeCount:'198' - }, - { - Name:'Salling', - Status:'1', - IsPaymentActive:'0 ', - Description:'', - DescriptionPublic:'', - IsOpen:'1 ', - CountOfHandicapPlaces:'0', - CountOfChargingStations:'0', - OpeningTimeDescription:'', - PayPeriodDescription:'', - PriceDescription:'', - PriceFreePeriod:'0', - PricePerMinut:'0', - AccessStreet:'Bom 3, Bom 2, Bom 1, ', - Mode:'1', - Longitude:'9.922735', - Latitude:'57.04758', - ClosedWeekDay:'0', - ClosedFrom:'00:00', - ClosedTo:'00:00', - PayPeriodWeekDay:'0', - PayPeriodFrom:'00:00', - PayPeriodTo:'00:00', - MaxCount:'312', - FreeCount:'282' - }, - { - Name:'Musikkens Hus', - Status:'1', - IsPaymentActive:'0 ', - Description:'', - DescriptionPublic:'', - IsOpen:'1 ', - CountOfHandicapPlaces:'0', - CountOfChargingStations:'0', - OpeningTimeDescription:'', - PayPeriodDescription:'', - PriceDescription:'', - PriceFreePeriod:'0', - PricePerMinut:'0', - AccessStreet:'Nyhavnsgade udkørsel, Nyhavnsgade udkørsel, Nyhavnsgade Indkørsel, ', - Mode:'1', - Longitude:'9.93311', - Latitude:'57.04737', - ClosedWeekDay:'0', - ClosedFrom:'00:00', - ClosedTo:'00:00', - PayPeriodWeekDay:'0', - PayPeriodFrom:'00:00', - PayPeriodTo:'00:00', - MaxCount:'285', - FreeCount:'285' - }, - { - Name:'Palads', - Status:'1', - IsPaymentActive:'0 ', - Description:'', - DescriptionPublic:'', - IsOpen:'1 ', - CountOfHandicapPlaces:'0', - CountOfChargingStations:'0', - OpeningTimeDescription:'', - PayPeriodDescription:'', - PriceDescription:'', - PriceFreePeriod:'0', - PricePerMinut:'0', - AccessStreet:'', - Mode:'1', - Longitude:'9.920601', - Latitude:'57.05014', - ClosedWeekDay:'0', - ClosedFrom:'00:00', - ClosedTo:'00:00', - PayPeriodWeekDay:'0', - PayPeriodFrom:'00:00', - PayPeriodTo:'00:00', - MaxCount:'475', - FreeCount:'383' - }, - { - Name:'Kongrescenter', - Status:'1', - IsPaymentActive:'0 ', - Description:'', - DescriptionPublic:'', - IsOpen:'1 ', - CountOfHandicapPlaces:'0', - CountOfChargingStations:'0', - OpeningTimeDescription:'', - PayPeriodDescription:'', - PriceDescription:'', - PriceFreePeriod:'0', - PricePerMinut:'0', - AccessStreet:'P Ind 1 - Frederikskildevej (5), P Ud - Vesterbro (4) cnt, P Ud - Vesterbro (3) cnt, P Ind - Vesterbro (1), P Ud - Vesterbro (2) cls, P Ud 2 - Frederikskildevej (6), ', - Mode:'1', - Longitude:'9.91458', - Latitude:'57.04456', - ClosedWeekDay:'0', - ClosedFrom:'00:00', - ClosedTo:'00:00', - PayPeriodWeekDay:'0', - PayPeriodFrom:'00:00', - PayPeriodTo:'00:00', - MaxCount:'700', - FreeCount:'691' - }, - { - Name:'GÃ¥sepigen', - Status:'1', - IsPaymentActive:'0 ', - Description:'', - DescriptionPublic:'', - IsOpen:'1 ', - CountOfHandicapPlaces:'0', - CountOfChargingStations:'0', - OpeningTimeDescription:'', - PayPeriodDescription:'', - PriceDescription:'', - PriceFreePeriod:'0', - PricePerMinut:'0', - AccessStreet:'Indkørsel fra Stengade, Udkørsel til Stengade, ', - Mode:'1', - Longitude:'9.91376', - Latitude:'57.04751', - ClosedWeekDay:'0', - ClosedFrom:'00:00', - ClosedTo:'00:00', - PayPeriodWeekDay:'0', - PayPeriodFrom:'00:00', - PayPeriodTo:'00:00', - MaxCount:'145', - FreeCount:'16' - }, - { - Name:'Kennedy Arkaden', - Status:'0', - IsPaymentActive:'0 ', - Description:'', - DescriptionPublic:'', - IsOpen:'1 ', - CountOfHandicapPlaces:'0', - CountOfChargingStations:'0', - OpeningTimeDescription:'', - PayPeriodDescription:'', - PriceDescription:'', - PriceFreePeriod:'0', - PricePerMinut:'0', - AccessStreet:'P Outgoing, P Ingoing, ', - Mode:'1', - Longitude:'9.918808', - Latitude:'57.04178', - ClosedWeekDay:'0', - ClosedFrom:'00:00', - ClosedTo:'00:00', - PayPeriodWeekDay:'0', - PayPeriodFrom:'00:00', - PayPeriodTo:'00:00', - MaxCount:'350', - FreeCount:'281' - }, - { - Name:'Føtex', - Status:'1', - IsPaymentActive:'0 ', - Description:'', - DescriptionPublic:'', - IsOpen:'1 ', - CountOfHandicapPlaces:'0', - CountOfChargingStations:'0', - OpeningTimeDescription:'', - PayPeriodDescription:'', - PriceDescription:'', - PriceFreePeriod:'0', - PricePerMinut:'0', - AccessStreet:'Udkørsel Fjordgade, Indkørsel Fjordgade, ', - Mode:'1', - Longitude:'9.924956', - Latitude:'57.04754', - ClosedWeekDay:'0', - ClosedFrom:'00:00', - ClosedTo:'00:00', - PayPeriodWeekDay:'0', - PayPeriodFrom:'00:00', - PayPeriodTo:'00:00', - MaxCount:'150', - FreeCount:'140' - }, - { - Name:'Friis', - Status:'1', - IsPaymentActive:'0 ', - Description:'', - DescriptionPublic:'', - IsOpen:'1 ', - CountOfHandicapPlaces:'0', - CountOfChargingStations:'0', - OpeningTimeDescription:'', - PayPeriodDescription:'', - PriceDescription:'', - PriceFreePeriod:'0', - PricePerMinut:'0', - AccessStreet:'', - Mode:'1', - Longitude:'9.927327', - Latitude:'57.04769', - ClosedWeekDay:'0', - ClosedFrom:'00:00', - ClosedTo:'00:00', - PayPeriodWeekDay:'0', - PayPeriodFrom:'00:00', - PayPeriodTo:'00:00', - MaxCount:'731', - FreeCount:'678' - }, - { - Name:'C W Obel', - Status:'1', - IsPaymentActive:'0 ', - Description:'', - DescriptionPublic:'', - IsOpen:'1 ', - CountOfHandicapPlaces:'0', - CountOfChargingStations:'0', - OpeningTimeDescription:'', - PayPeriodDescription:'', - PriceDescription:'', - PriceFreePeriod:'0', - PricePerMinut:'0', - AccessStreet:'Indkørsel Badehusvej, Udkørsel Badehusvej, ', - Mode:'1', - Longitude:'9.910837', - Latitude:'57.05243', - ClosedWeekDay:'0', - ClosedFrom:'00:00', - ClosedTo:'00:00', - PayPeriodWeekDay:'0', - PayPeriodFrom:'00:00', - PayPeriodTo:'00:00', - MaxCount:'376', - FreeCount:'376' - }, - { - Name:'Budolfi Plads', - Status:'1', - IsPaymentActive:'0 ', - Description:'', - DescriptionPublic:'', - IsOpen:'1 ', - CountOfHandicapPlaces:'0', - CountOfChargingStations:'0', - OpeningTimeDescription:'', - PayPeriodDescription:'', - PriceDescription:'', - PriceFreePeriod:'0', - PricePerMinut:'0', - AccessStreet:'Indkørsel fra gaden Budolfi Plads, Udkørsel til Algade, Indkørsel til privat p-omrÃ¥de, Indkørsel fra Algade, ', - Mode:'1', - Longitude:'9.9183', - Latitude:'57.0475', - ClosedWeekDay:'0', - ClosedFrom:'00:00', - ClosedTo:'00:00', - PayPeriodWeekDay:'0', - PayPeriodFrom:'00:00', - PayPeriodTo:'00:00', - MaxCount:'157', - FreeCount:'135' - } - ] -} \ No newline at end of file