Skip to content

Commit c466401

Browse files
committed
Fix incomplete urls in lipas and osm data
1 parent 6e4c1b3 commit c466401

File tree

4 files changed

+21
-0
lines changed

4 files changed

+21
-0
lines changed

backend/lambda_functions/lipas_loader/lipas_loader.py

+4
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ def get_feature(self, sports_place_id: int): # type: ignore[override]
145145
season = Season.ALL_YEAR.value
146146
tarmo_category = self.category_from_code[type_code]
147147

148+
# validate/fix URL!
149+
if "www" in data and data["www"] and not data["www"].startswith("http"):
150+
data["www"] = "https://" + data["www"]
151+
148152
flattened = {
149153
**data,
150154
**props,

backend/lambda_functions/osm_loader/osm_loader.py

+6
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ def get_feature(self, element: Dict[str, Any]) -> Optional[dict]: # type: ignor
149149
if geom.is_empty:
150150
return None
151151

152+
# validate/fix URL!
153+
if "website" in tags:
154+
tags["www"] = tags.pop("website")
155+
if tags["www"] and not tags["www"].startswith("http"):
156+
tags["www"] = "https://" + tags["www"]
157+
152158
# OSM ids are *only* unique *within* each type!
153159
# SQLAlchemy merge() doesn't know how to handle unique constraints that are not
154160
# pk. Therefore, we will have to specify the primary key here (not generated in

backend/test/test_lipas_loader.py

+9
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ def test_get_sport_place_talviuintipaikka(loader):
157157
assert sport_place["tarmo_category"] == "Talviuinti"
158158

159159

160+
def test_get_sport_place_incomplete_url_fixed(loader):
161+
sport_place = loader.get_feature(506521)
162+
assert sport_place["geom"] == "MULTIPOINT (23.7443451904576 61.3050219780947)"
163+
assert sport_place["season"] == "Koko vuosi"
164+
assert sport_place["table"] == "lahiliikuntapaikka"
165+
assert sport_place["tarmo_category"] == "Ulkoilupaikat"
166+
assert sport_place["www"] == "https://www.lempaala.fi"
167+
168+
160169
def assert_data_is_imported(main_db_params):
161170
conn = psycopg2.connect(**main_db_params)
162171
try:

backend/test/test_osm_loader.py

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"amenity": "parking",
8484
"capacity": "5",
8585
"parking": "surface",
86+
"website": "www.parkkipaikka.fi",
8687
},
8788
},
8889
{
@@ -273,6 +274,7 @@ def test_get_customer_parking_feature(parking_loader, parking_data):
273274
assert customer_parking["osm_type"] == "node"
274275
assert customer_parking["geom"].startswith("POINT")
275276
assert customer_parking["tags"]
277+
assert customer_parking["tags"]["www"] == "https://www.parkkipaikka.fi"
276278
assert customer_parking["type_name"] == "Asiakaspysäköinti"
277279

278280

0 commit comments

Comments
 (0)