Skip to content

Commit

Permalink
Add support for "amzn.eu" URLs
Browse files Browse the repository at this point in the history
The current method to unshorten urls doesn't work for amzn.eu URLs.
Using a HEAD request will return 404 with them, but using a GET works.
  • Loading branch information
Aritzherrero4 committed Sep 9, 2022
1 parent e7793e6 commit 8b4204a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ def newReferURL(pcode):

#Expand shorted URL (amzn.to links) to normal Amazon URL
def unshortURL(url):
session = requests.Session() # so connections are recycled
resp = session.head("https://"+url, allow_redirects=True)
resp = requests.get("https://"+url)
return resp.url

#Filter the msg text to extract the URL if found. Then send the corresponding reply
Expand All @@ -54,6 +53,9 @@ def filterText(update, context):
pCode=""
msg = update.message.text
start = msg.find("amzn.to")
if start!=-1:
msg = unshortURL(msg[start:].split()[0])
start = msg.find("amzn.eu")
if start!=-1:
msg = unshortURL(msg[start:].split()[0])
start = msg.find(searchURL)
Expand Down

0 comments on commit 8b4204a

Please sign in to comment.