Skip to content

Commit a2cb0b4

Browse files
committed
Also sorting urls
1 parent 8648d5a commit a2cb0b4

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

telegram/utils/helpers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ def _timestamp(dt_obj):
4242
# Python < 3.3 (incl 2.7)
4343
from time import mktime
4444

45+
4546
def _timestamp(dt_obj):
4647
return mktime(dt_obj.timetuple())
4748

@@ -146,6 +147,8 @@ def extract_urls(message):
146147
# Strip trailing slash from URL so we can compare them for equality
147148
stripped_urls = [x[:-1] if x[-1] == '/' else x for x in all_urls]
148149

150+
sorted_urls = sorted(stripped_urls, key=str.lower)
151+
149152
# Remove exact duplicates
150-
urls = OrderedDict({k: None for k in stripped_urls})
153+
urls = OrderedDict({k: None for k in sorted_urls})
151154
return list(urls.keys())

tests/test_helpers.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ def test_extract_urls_entities(self):
5858

5959
assert len(result) == 2
6060
assert (test_entities[0]['url'][:-1] == result[0])
61-
assert (result[0] == 'http://github.com')
6261
assert (test_entities[2]['url'] == result[1])
6362

6463
def test_extract_urls_caption(self):

0 commit comments

Comments
 (0)