0

所以,这是我的程序。它的作用是在我所在的论坛上出现新的 pm 时向我发送一条短信。问题是它不只发送一个,而是发送数百个。

我该如何解决?我假设一个break声明,但我不知道如何措辞。

import urllib2
from twilio.rest import TwilioRestClient
webp=urllib2.urlopen("http://hackforums.net").read()
words = urllib2.urlopen("http://hackforums.net").read()

word = 'titled'
while True:
    for word in words:
        if word in words:
            ACCOUNT_SID = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXx"
            AUTH_TOKEN = "XXXXXXXXXXXXXXXXXXXXXXXXXXXx"

            client = TwilioRestClient(ACCOUNT_SID, AUTH_TOKEN)

            message = client.sms.messages.create(to="XXXto", from_="XXXfrom",
                body="You have a new PM")

然后我正在使用:

import os
import time

while True:
    os.system("python newway.py")

print 'done'

打开它。

4

1 回答 1

2

假设顶部的代码块是newway.py,您无法检查内容是否是新的,并且您调用它的方式只是一遍又一遍地运行它。

您需要实现某种跟踪状态的方法(我建议使用文件),并跟踪某些内容是否是新的,并且仅在有新内容时发送消息。

于 2012-07-30T23:01:38.913 回答