私が書いたコードを実行すると少し問題があります。intをPythonを使ってstrsに変換する
import requests
import time
import datetime
import os
def datarequest():
url = 'http://csgoroll.com/v1/roulette/state?token=bcb78foobar7b9' # Could add a + pls str(pagesomething) to add on to the url so that it would update
sourcecode = requests.get(url) # requests the data from the site
obj = sourcecode.json()
###
str1 = ''.join(str(e) for e in obj['rolls'])
for obj['roll'] in str1:
rolldata = obj['roll'] in str1
file = open("newfile.txt", "w")
file.write(rolldata)
file.close()
file = open('newfile.txt', 'r')
print(file.read())
###
if __name__ == '__main__':
while True:
datarequest()
time.sleep(120) # these are seconds
私はこれを実行するたびに、私はエラーだ「はTypeError:書き込みを()の引数はstrをしなければならない、BOOLない」まだ私が参加文を使用して文字列に変換しています、と私は置く場所が表示されませんどこでもboolステートメント。
誰かが私の問題を解決するために文字列に正しく変換してintを導くことができれば、私のプログラム内でこの問題が発生している理由に関する一般的なアドバイスと一緒に、
「rolldata」に割り当てられます。 – Shadow
rolldata = obj [str1の 'roll']はboolです。 –
サイドノート、私はstr1のobj ['roll']のためにかなり確信しています:文字列を反復しているので、あなたがしたいことではありません... – Iluvatar