2017-12-30 14 views
0

나는 speedtest-cli 및 subprocess를 사용하는 tweepy를 사용하여 Python 기반 twitter bot에서 일하고 있습니다. 우리가 지불하는 것 아래에있는 경우 매 ISP에서 인터넷 속도와 트윗을 매 45 분마다 얻습니다. 그러나 문제가 있습니다. 테스트를 위해 필자는 파이썬 3 프린트 기능을 사용하여 파이썬 2.7에서 가져온 파일과 파이썬 2.7에서 모두 동일한 두 파일을 만들었습니다. 하나는 정적이며, Tweepy aspect를 테스트 할 수있는 가장 빠른 결과를 얻었고, 다른 하나는 똑같은 이름의 변수에 쓰는 반면, 다른 하나는 Speedtest를 실행합니다.tweepy API 게시글에서 update_status로 오류 게시

실제 버전은

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 기능을 배치하고 밝혀 10 이상, 그것은 실수, testresint 것으로 판단 후 else 문을 것입니다. 내가 권고 한대로 10.030 전에 float을 삭제했습니다. 나는 아직도 잘못 된 것이 무엇인지 알 수 없다.

+0

'testresint, testresnone = testressplit.split ('Mbit/s ')'에'testresnone'을 재설정하고 있습니다. 그 맞습니까? 또한,'10.0'에서'float()'을 호출하는 것은 필요하지 않습니다. – srig

+0

예,'testresnone'은 하위 프로세스의 출력이 필요한 부분 만 가져갈 수있는 자리 표시 자이며 고맙습니다. –

+0

이전 문장에서'testresraw.split ('Download :') [0]'을'testresnone'으로 지정한 다음'testressplit.split ('Mbit/s') [1]'로 변경했습니다. 그것이 필요한지 궁금해하고있었습니다. – srig

답변

0

if testresint<float(10.0)if float(testresint)<float(10.0)으로 변경하여 문제를 해결했습니다.