Support both 'm' and 'smid' parameters if present
This commit is contained in:
24
bot/bot.py
24
bot/bot.py
@@ -13,8 +13,8 @@ from selenium.webdriver.common.keys import Keys
|
||||
from selenium.webdriver.common.by import By
|
||||
from selenium.webdriver.chrome.options import Options
|
||||
from selenium import webdriver
|
||||
from telegram import Update, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup
|
||||
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext
|
||||
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
|
||||
from telegram.ext import Updater, MessageHandler, Filters, CallbackContext
|
||||
from amazon_product import AmazonProduct
|
||||
|
||||
|
||||
@@ -44,8 +44,8 @@ def load_page(url: str, driver: webdriver, screenshot_type=""):
|
||||
|
||||
|
||||
def extract_amazon_url_with_referer(text: str):
|
||||
productCode = ""
|
||||
extraparams = ""
|
||||
product_code = ""
|
||||
extra_params = ""
|
||||
|
||||
start = text.find("amzn.to")
|
||||
if start != -1:
|
||||
@@ -56,13 +56,15 @@ def extract_amazon_url_with_referer(text: str):
|
||||
start = text.find(constants.searchURL)
|
||||
if start != -1:
|
||||
text = f"https://{text[start:].split(' ')[0]}"
|
||||
m = re.search(r'(?:dp\/[\w]*)|(?:gp\/product\/[\w]*)',text) # Gets product code in amazon
|
||||
m_e = re.search(r'(?:&m=[\w]*)',text) # Gets vendor and keeps it
|
||||
if m != None:
|
||||
productCode = m.group(0)
|
||||
if m_e != None:
|
||||
extraparams = m_e.group(0)
|
||||
return helpers.new_refer_url(productCode, extraparams)
|
||||
product_code_regex_result = re.search(r'(?:dp\/[\w]*)|(?:gp\/product\/[\w]*)',text) # Gets product code in amazon
|
||||
vendor_and_smid_result = re.findall(r'(?:[&|?]m=[\w]*)|(?:[&|?]smid=[\w]*)', text) # Gets vendor and smid parameter that it seems to be like a variant and keeps it
|
||||
if product_code_regex_result:
|
||||
product_code = product_code_regex_result.group(0)
|
||||
if vendor_and_smid_result:
|
||||
extra_params = (''.join(str(w) for w in vendor_and_smid_result if w is not None))
|
||||
extra_params.replace('?','&')
|
||||
|
||||
return helpers.new_refer_url(product_code, extra_params)
|
||||
|
||||
|
||||
def resolve_captcha(driver: webdriver):
|
||||
|
||||
Reference in New Issue
Block a user