使用update_status的tweepy API发布文本时出错

问题描述 投票:0回答:1

我正在研究一个基于Python的twitter机器人,使用tweepy,使用speedtest-cli和subprocess来获取我的互联网速度和推特,每隔45分钟就在我的ISP上,如果它在我们支付的费用之下,但是,我遇到了问题。为了进行测试,我制作了2个文件,两个文件在导入方面都相同,在Python 2.7中都使用Python 3打印功能。一个是静态的,设置速度最快的结果,允许我测试Tweepy方面,而另一个运行speedtest并将其写入一个同名的变量。

真正的版本是

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函数,以告诉我它在哪里弄乱,事实证明,在判断else不小于10,错误地,它将进入testresint声明。我按照建议在10.0之前删除了float。我仍然无法弄清楚出了什么问题。

python python-2.7 twitter automated-tests tweepy
1个回答
0
投票

我设法通过将if testresint<float(10.0)改为if float(testresint)<float(10.0)来解决这个问题。

© www.soinside.com 2019 - 2024. All rights reserved.