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.common.by import By
|
||||||
from selenium.webdriver.chrome.options import Options
|
from selenium.webdriver.chrome.options import Options
|
||||||
from selenium import webdriver
|
from selenium import webdriver
|
||||||
from telegram import Update, ForceReply, InlineKeyboardButton, InlineKeyboardMarkup
|
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
|
||||||
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, CallbackContext
|
from telegram.ext import Updater, MessageHandler, Filters, CallbackContext
|
||||||
from amazon_product import AmazonProduct
|
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):
|
def extract_amazon_url_with_referer(text: str):
|
||||||
productCode = ""
|
product_code = ""
|
||||||
extraparams = ""
|
extra_params = ""
|
||||||
|
|
||||||
start = text.find("amzn.to")
|
start = text.find("amzn.to")
|
||||||
if start != -1:
|
if start != -1:
|
||||||
@@ -56,13 +56,15 @@ def extract_amazon_url_with_referer(text: str):
|
|||||||
start = text.find(constants.searchURL)
|
start = text.find(constants.searchURL)
|
||||||
if start != -1:
|
if start != -1:
|
||||||
text = f"https://{text[start:].split(' ')[0]}"
|
text = f"https://{text[start:].split(' ')[0]}"
|
||||||
m = re.search(r'(?:dp\/[\w]*)|(?:gp\/product\/[\w]*)',text) # Gets product code in amazon
|
product_code_regex_result = 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
|
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 m != None:
|
if product_code_regex_result:
|
||||||
productCode = m.group(0)
|
product_code = product_code_regex_result.group(0)
|
||||||
if m_e != None:
|
if vendor_and_smid_result:
|
||||||
extraparams = m_e.group(0)
|
extra_params = (''.join(str(w) for w in vendor_and_smid_result if w is not None))
|
||||||
return helpers.new_refer_url(productCode, extraparams)
|
extra_params.replace('?','&')
|
||||||
|
|
||||||
|
return helpers.new_refer_url(product_code, extra_params)
|
||||||
|
|
||||||
|
|
||||||
def resolve_captcha(driver: webdriver):
|
def resolve_captcha(driver: webdriver):
|
||||||
|
|||||||
Reference in New Issue
Block a user