带有update_status的 tweepy API 发布文本时出错



我正在使用tweepy开发一个基于Python的Twitter机器人,该机器人使用speedtest-cli和子进程来获取我的互联网速度,如果低于我们支付的费用,则每45分钟向我的ISP发推文,但是,我遇到了问题。为了进行测试,我制作了 2 个文件,这两个文件在导入中相同,并且在 Python 2.7 中使用 Python 3 打印函数。一个有一个静态的、设置的速度测试结果,允许我测试 Tweepy 方面,而另一个运行速度测试并将其写入一个同名变量。

真实版本是

while True:
testresraw = subprocess.check_output('speedtest --no-upload', shell=True) #Test speed and get output
testresnone,testressplit = testresraw.split('Download: ')#Remove text before the download speed
testresint,testresnone = testressplit.split('Mbit/s')#Remove text after download speed
float(testresint)#Make sure download speed is a number
if testresint<float(10.0):
    statustext= ('My download speed is currently %d MB/s, which is less than the 10 we pay @CenturyLink for' % (testresint))
    api.update_status(status=statustext)
    time.sleep(2700)
else:
    time.sleep(2700)

测试版本是

testresint = 1
if testresint<float(10.0):
    statustext = ('My download speed is currently %d MB/s, which is less than the 10 we pay @CenturyLink for' % (testresint))
    api.update_status(status=statustext)
    time.sleep(2700)
else:
    time.sleep(2700)

只有测试版本有效,我不知道为什么。

编辑:我放置了一些print函数来显示它在哪里搞砸了,事实证明,在错误地判断testresint不少于10之后,它将进入else语句。我按照建议删除了 10.0 之前的float。我仍然无法弄清楚出了什么问题。

我设法通过将if testresint<float(10.0)更改为if float(testresint)<float(10.0)来修复它。

最新更新