您好,我目前正在监视某个网站上的特定产品。我可以通过运行脚本来让twilio发短信给我,但无论是否有库存,它都不会更新我。以下是与此过程有关的代码:
import requests,json,re,time,sys
import twilio
from bs4 import BeautifulSoup
from twilio.rest import Client
timeout = [] #Define global timeout list, this list is used to blacklist pops once they've sent one notification so you don't get 100 notifications for an in stock pop.
def url_to_html(url):
r = requests.get(url)
soup = BeautifulSoup(r.text, 'html.parser')
return soup
def hottopic_stock(url):
soup = url_to_html(url)
html_source = soup.find_all("div", {"class" : "availability-msg"})
match = re.search(r'\bIn Stock\b',str(html_source))
if match: #Return true if In Stock
return False
def CheckFunko(Site, Title, url):
global timout
print("Checking: "+Site+" "+Title+" "+url)
#this is where I want to combine the functions
if Site == 'Hot Topic':
status = hottopic_stock(url)
else:
status = False
if status == True:
client = Client("Api key, twilio account number")
client.messages.create(to="My phone number",
from_="Twillo Phone number",
body="Duffer Brothers in stock!"
答案 0 :(得分:0)
问题似乎是您的hottopic_stock
函数,因为在发送过程中,它仅返回False
(如果正则表达式匹配)或None
(如果正则表达式不匹配)您检查的代码,状态是否为True
,这种情况永远不会发生。也许尝试一下(如果正则表达式确实匹配并且未测试此代码,我想这是有货的东西):
def hottopic_stock(url):
soup = url_to_html(url)
html_source = soup.find_all("div", {"class" : "availability-msg"})
match = re.search(r'\bIn Stock\b',str(html_source))
return match is not None