Skip to content

Commit

Permalink
more accurate common regex (bugfix: negative and 1 digt coordinates)
Browse files Browse the repository at this point in the history
  • Loading branch information
papko26 committed Dec 2, 2024
1 parent 1be78bc commit 455473d
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/gtw.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,12 @@ def extract_coordinates_with_regex(url):
# Sometimes /places link may contain coordinates of the location, which
# user browsed after he chosed the destination.
# Lets ensure we will not try to parse it.
if "/place/" in url:
# Same for /dir/ locations - it is google maps directions (route).
if "/place/" in url or "/dir/":
logger.debug("fastrrack: it is a 'places' link, parsing skipped")
return None
# Regex pattern to match latitude and longitude pairs
pattern = r".*?(\d\d\.\d\d\d+).*?(\d\d\.\d\d\d+)"
pattern = r"(-?\d+(\.\d+)?),\s*(-?\d+(\.\d+)?)"
match = re.search(pattern, url)
if match:
# Extract latitude and longitude from groups
Expand Down

0 comments on commit 455473d

Please sign in to comment.