0
所以有这个网站发布我想在一天中的任意时间购买一段时间的东西,我想写一些东西给我的手机发送消息时新的网址发布到该网页。在一个类内的函数内调用一个函数
我计划通过计算页面上的链接数量(因为它很少更新),并每隔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语句确定是否要发送消息作为平等的,但在循环不停地运行。我是否以正确的方式调用循环函数中的函数?
哪里self.phone定义?我只看到自己的电话的定义。 – MathSquared
另外,__phone的第一行是'self = phone',应该做什么? – MathSquared
这是我第一次为我自己创建的项目编写自己的课程。我认为self = phone就像消息变量和电话功能之间的'连接'。 – e1v1s