1212)
1313
1414
15+ def remove_troublesome_chars (string : str ):
16+ troublesome_chars = {'"' : "" , "'" : "" , "\n " : "" }
17+ for k , v in troublesome_chars .items ():
18+ string = string .replace (k , v )
19+ return string
20+
21+
1522def retry_get (url , retries = 3 , timeout = 4 ):
1623 retry = Retry (total = retries )
1724 session = requests .Session ()
@@ -55,13 +62,13 @@ def query_osm(changeset_ids: list, changeset_results):
5562
5663 for changeset in tree .iter ("changeset" ):
5764 id = changeset .attrib ["id" ]
58- username = changeset .attrib ["user" ]
65+ username = remove_troublesome_chars ( changeset .attrib ["user" ])
5966 userid = changeset .attrib ["uid" ]
6067 comment = created_by = None
6168 for tag in changeset .iter ("tag" ):
6269 if tag .attrib ["k" ] == "comment" :
6370 try :
64- comment = tag .attrib ["v" ]. replace ( " \n " , " " )
71+ comment = remove_troublesome_chars ( tag .attrib ["v" ])
6572 except AttributeError :
6673 pass
6774 if tag .attrib ["k" ] == "created_by" :
@@ -76,17 +83,6 @@ def query_osm(changeset_ids: list, changeset_results):
7683 return changeset_results
7784
7885
79- def add_to_properties (attribute : str , feature : dict , new_properties : dict ):
80- """Adds attribute to new geojson properties if it is needed."""
81- if attribute != "comment" :
82- new_properties [attribute .replace ("@" , "" )] = feature ["properties" ][attribute ]
83- else :
84- new_properties [attribute .replace ("@" , "" )] = feature ["properties" ]["tags" ][
85- attribute
86- ]
87- return new_properties
88-
89-
9086def remove_noise_and_add_user_info (json : dict ) -> dict :
9187 """Delete unwanted information from properties."""
9288 logger .info ("starting filtering and adding extra info" )
0 commit comments