Skip to content

Commit 080baf8

Browse files
committed
now working
1 parent 7655cea commit 080baf8

File tree

1 file changed

+14
-23
lines changed

1 file changed

+14
-23
lines changed

mapswipe_workers/mapswipe_workers/utils/api_calls.py

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -42,53 +42,44 @@ def query_osm(changeset_id: int):
4242
return response
4343

4444

45-
def add_to_properties(attribute: str, feature: dict, new_properties: dict):
46-
"""Adds attribute to new geojson properties if it is needed."""
47-
if attribute != "comment":
48-
new_properties[attribute.replace("@", "")] = feature["properties"][attribute]
49-
else:
50-
new_properties[attribute.replace("@", "")] = feature["properties"]["tags"][
51-
attribute
52-
]
53-
return new_properties
54-
55-
5645
def remove_noise_and_add_user_info(json: dict) -> dict:
5746
"""Delete unwanted information from properties."""
5847
logger.info("starting filtering and adding extra info")
5948

60-
wanted_attributes = [
61-
"@changesetId",
62-
"@lastEdit",
63-
"@osmId",
64-
"@version",
65-
"source",
66-
"comment",
67-
]
6849
changeset_results = {}
6950
missing_rows = {
7051
"@changesetId": 0,
7152
"@lastEdit": 0,
7253
"@osmId": 0,
7354
"@version": 0,
7455
"source": 0,
75-
"comment": 0,
56+
"hashtags": 0,
7657
}
7758

7859
for feature in json["features"]:
7960
new_properties = {}
80-
for attribute in wanted_attributes:
61+
for attribute in missing_rows.keys():
8162
try:
82-
new_properties = add_to_properties(attribute, feature, new_properties)
63+
new_properties[attribute.replace("@", "")] = feature["properties"][
64+
attribute
65+
]
8366
except KeyError:
84-
missing_rows[attribute] += 1
67+
if attribute != "hashtags":
68+
missing_rows[attribute] += 1
8569
changeset_id = new_properties["changesetId"]
8670

8771
# if changeset_id already queried, use stored result
8872
if changeset_id not in changeset_results.keys():
8973
changeset_results[changeset_id] = query_osm(changeset_id)
9074
new_properties["username"] = changeset_results[changeset_id]["user"]
9175
new_properties["userid"] = changeset_results[changeset_id]["uid"]
76+
try:
77+
new_properties["hashtags"] = changeset_results[changeset_id]["tags"][
78+
"hashtags"
79+
]
80+
except KeyError:
81+
missing_rows["hashtags"] += 1
82+
9283
feature["properties"] = new_properties
9384
logger.info("finished filtering and adding extra info")
9485
if any(x > 0 for x in missing_rows.values()):

0 commit comments

Comments
 (0)