[英]Calling a function within a function within a class
因此,有一个网站发布了我想在一天的随机时间有限的时间内发布的商品,并且我想写一些东西来在新的URL发布到该手机时向手机发送消息。
我计划通过计算页面上的链接数(由于很少更新)来进行此操作,并每隔5分钟检查一次,而不是之前的5分钟,然后在5分钟之后再检查之前的10分钟, 5分钟后,检查15分钟之前的时间...如果大于原来的时间,请向我的手机发送一条消息。 这是我到目前为止的内容:
class url_alert:
url = ''
def link_count(self):
notifyy=True
while notifyy:
try:
page = urllib.request.urlopen(self.url)
soup = bs(page, "lxml")
links=[]
for link in soup.findAll('a'):
links.append(link.get('href'))
notifyy=False
print('found', int(len(links)), 'links')
except:
print('Stop making so many requests')
time.sleep(60*5)
return len(links)
def phone(self):
self= phone
phone.message = client.messages.create(to="", from_="",body="")
print('notified')
def looper(self):
first_count = self.link_count()
print('outside while')
noty = True
while noty:
try:
second_count = self.link_count()
print('before compare')
if second_count == first_count:
self.phone()
noty = False
except:
print('not quite...')
time.sleep(60)
alert = url_alert()
alert.looper()
作为测试,我决定设置if语句,该语句确定是否相等地发送消息,但循环保持运行状态。 我是否以正确的方式调用了looper函数中的函数?
看起来您需要像现在一样消除try块,如果self.phone()接受异常,则您将永远不会离开循环
def looper(self):
first_count = self.link_count()
while True:
if first_count != self.link_count():
self.phone()
break
time.sleep(60)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.