2017-12-30 55 views
0

私は、speedtest-cliとサブプロセスを使用してtweepyを使用してPythonベースのtwitter botで作業しています。しかし、私は問題を抱えています。テストのために、私は2つのファイルを作成しました。どちらもインポートでは同じで、両方ともPython 3でPython 3の印刷機能を使用していました。私はTweepyのアスペクトをテストできるように静的な、設定されたスピードテスト結果を持っていますが、他のスピードテストはスピードテストを実行し、同じ名前の変数に書き込みます。tweepy APIでの投稿のエラー

本当のバージョンが

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) 

テスト版作品であると、私はその理由を把握することはできません。

編集:私はそれを台無しにして、そしてそれは結局のところ、それはtestresintが誤って、10以上であると判断した後、elseステートメントに起こっている場所に私を示すために、いくつかのprint機能を配置しました。私はアドバイスとして10.0の前に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)に変更して修正できました。

関連する問題