From 2404494c31debd91c76fb6560b8945b1af3dc539 Mon Sep 17 00:00:00 2001 From: Bob Mottram Date: Wed, 16 Oct 2024 13:52:39 +0100 Subject: [PATCH] Include http prefix when searching for map links --- maps.py | 7 +++++++ tests.py | 13 ++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/maps.py b/maps.py index 50424d759..47f49ce7b 100644 --- a/maps.py +++ b/maps.py @@ -599,6 +599,13 @@ def get_map_links_from_post_content(content: str, session) -> []: url = url.split('<')[0] if not url: continue + + # complete the url + if 'http://' + url in content: + url = 'http://' + url + elif 'https://' + url in content: + url = 'https://' + url + zoom, latitude, longitude = \ geocoords_from_map_link(url, osm_domain, session) if not latitude: diff --git a/tests.py b/tests.py index 69db47d46..da81c5003 100644 --- a/tests.py +++ b/tests.py @@ -8097,12 +8097,19 @@ def _test_combine_lines(): def _test_hashtag_maps(): print('hashtag_maps') + session = create_session(None) + + expected_link = "https://osm.org/go/0G0dJ91-?m=&relation=62414" + content = "

@dan Test 4 geo link https://osm.org/go/0G0dJ91-?m=&relation=62414

" + map_links = get_map_links_from_post_content(content, session) + if expected_link not in map_links: + print(str(map_links)) + assert expected_link in map_links content = \ "

This is a test, with a geo link " + \ "geo:52.90820,-3.59817;u=35, and some other stuff," + \ " with commas

" - session = None map_links = get_map_links_from_post_content(content, session) link = "geo:52.90820,-3.59817" if link not in map_links: @@ -8133,7 +8140,7 @@ def _test_hashtag_maps(): "class=\"mention hashtag\" rel=\"tag\" tabindex=\"10\">#" + \ "AnotherHashtag

" map_links = get_map_links_from_post_content(content, session) - link = "www.google.com/maps/@52.217291,-3.0811865,20.04z" + link = "https://www.google.com/maps/@52.217291,-3.0811865,20.04z" assert link in map_links session = None zoom, latitude, longitude = \ @@ -8143,7 +8150,7 @@ def _test_hashtag_maps(): assert int(latitude * 1000) == 52217 assert longitude assert int(longitude * 1000) == -3081 - link = "www.openstreetmap.org/#map=19/52.90860/-3.59917" + link = "https://www.openstreetmap.org/#map=19/52.90860/-3.59917" assert link in map_links zoom, latitude, longitude = \ geocoords_from_map_link(link, 'openstreetmap.org', session)