diff --git a/server/src/unshorten.py b/server/src/unshorten.py deleted file mode 100644 index cfe10b7..0000000 --- a/server/src/unshorten.py +++ /dev/null @@ -1,17 +0,0 @@ -import re -import requests - - -def unshorten_twitter(url): - pattern = re.compile(r"(.*?)<\/title>") - - response = requests.get( - url=url, - headers={"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:124.0) Gecko/20100101 Firefox/124.0"} - ) - - match = pattern.search(response.text) - if match: - return match.group(1) - else: - return None diff --git a/server/src/unshorteners.py b/server/src/unshorteners.py new file mode 100644 index 0000000..dea5a6a --- /dev/null +++ b/server/src/unshorteners.py @@ -0,0 +1,22 @@ +"""Unshortening functions""" +import re +import requests + + +def unshorten_twitter(url): + """Retrieve the actual URL behind a Twitter URL.""" + pattern = re.compile(r"<title>(.*?)<\/title>") + + response = requests.get( + url=url, + headers={ + "User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:124.0) Gecko/20100101 Firefox/124.0" + }, + timeout=4 + ) + + match = pattern.search(response.text) + if match: + return match.group(1) + + return None