Нет кода цикла while:
Код: Выделить всё
import json
import xmltodict
import time
url = "https://pobb.in/DrX67Cqoz5cV/xml"
response = requests.get(url)
def xmlToJson():
with open ("build.xml", "w") as xml_file:
xml_file.write(response.text)
with open("build.xml") as xml_file:
data_dict = xmltodict.parse(xml_file.read())
json_data = json.dumps(data_dict)
with open("build.json", "w") as json_file:
json_file.write(json.dumps(json.loads(json_data), indent=4))
#xmlToJson()
def findUniques():
with open('build.json', "r") as f:
data = json.loads(f.read())
x=0
try:
#data = data['PathOfBuilding']['Items']['Item'][integer]['#text']
data = data['PathOfBuilding']['Items']['Item'][x]['#text']
print(data)
if "UNIQUE" in data:
print(f"Item Is Unique")
elif "RARE" in data:
print(f"Item Is Rare")
x+=1
except IndexError:
print("IndexError")
pass
findUniques()
Код: Выделить всё
import json
import xmltodict
import time
url = "https://pobb.in/DrX67Cqoz5cV/xml"
response = requests.get(url)
def xmlToJson():
with open ("build.xml", "w") as xml_file:
xml_file.write(response.text)
with open("build.xml") as xml_file:
data_dict = xmltodict.parse(xml_file.read())
json_data = json.dumps(data_dict)
with open("build.json", "w") as json_file:
json_file.write(json.dumps(json.loads(json_data), indent=4))
#xmlToJson()
def findUniques():
with open('build.json', "r") as f:
data = json.loads(f.read())
x=0
while True:
try:
#data = data['PathOfBuilding']['Items']['Item'][integer]['#text']
data = data['PathOfBuilding']['Items']['Item'][x]['#text']
print(data)
if "UNIQUE" in data:
print(f"Item Is Unique")
elif "RARE" in data:
print(f"Item Is Rare")
x+=1
except IndexError:
print("IndexError")
break
findUniques()
Код: Выделить всё
File "g:\Coding\Python\2024\poetest\pobtest.py", line 50, in
findUniques()
File "g:\Coding\Python\2024\poetest\pobtest.py", line 36, in findUniques
data = data['PathOfBuilding']['Items']['Item'][x]['#text']
~~~~^^^^^^^^^^^^^^^^^^
TypeError: string indices must be integers, not 'str'
При необходимости может быть указан любой другой код/информация.
Подробнее здесь: https://stackoverflow.com/questions/786 ... ot-without