@@ -371,22 +371,30 @@ def get_coordinates_from_place_id(place_id, api_key):
371
371
return None
372
372
373
373
374
- def extract_coordinates_with_regex (url ):
374
+ def extract_coordinates_with_regex (url , last_resort = False ):
375
375
try :
376
376
# Sometimes /places link may contain coordinates of the location, which
377
377
# user browsed after he chosed the destination.
378
378
# Lets ensure we will not try to parse it.
379
379
# Same for /dir/ locations - it is google maps directions (route).
380
- if url and ("/place/" in url or "/dir/" in url ):
381
- logger .debug ("fastrrack: it is a 'places' or 'dir' link, parsing skipped" )
382
- return None
380
+ if not url :
381
+ logger .error ("extract_crds: no url passed" )
382
+ if not last_resort :
383
+ if "/place/" in url or "/dir/" in url :
384
+ logger .debug ("extract_crds: it is a 'places' or 'dir' link, parsing skipped" )
385
+ return None
386
+ if last_resort :
387
+ logger .info ("extract_crds_last_resort: lemme try to find any coords no matter what" )
388
+
383
389
# Regex pattern to match latitude and longitude pairs
384
390
pattern = r"([-+]?\d+(?:\.\d+)?),\s*([-+]?\d+(?:\.\d+)?)"
385
391
match = re .search (pattern , url )
386
392
if match :
387
393
# Extract latitude and longitude from groups
388
394
latitude , longitude = match .groups ()
389
- return {"latitude" : latitude , "longitude" : longitude }
395
+ return {"extract_crds: latitude" : latitude , "longitude" : longitude }
396
+ else :
397
+ logger .debug ("extract_crds: failed to parse cords" )
390
398
except Exception as e :
391
399
logger .error (f"Error extracting coordinates: { e } " )
392
400
return None
@@ -414,6 +422,8 @@ def get_wise_link(google_link: str, api_key):
414
422
logger .debug ("get_wise_link: Trying places API" )
415
423
cid = places_api_parse_cid (resolved_url )
416
424
crds = get_coordinates_from_place_id (cid , api_key )
425
+ if not crds :
426
+ crds = extract_coordinates_with_regex (resolved_url , last_resort = True )
417
427
if not crds :
418
428
logger .error ("get_wise_link: Every attempt to get coordinates failed" )
419
429
return None
0 commit comments