Answer the question
In order to leave comments, you need to log in
How to fix errors in python code?
This code should display items from the steam inventory and their cost
. I don't understand python code I need help fixing errors in the code
import time
import requests
wear_list = ['Factory New', 'Minimal Wear', 'Field-Tested', 'Well-Worn', 'Battle-Scarred']
INVENTORY_URL = ' http://steamcommunity.com/profiles/{} /inventory/js... '
MARKET_URL = ' steamcommunity.com/market/priceoverview '
def get_inventory(steamid):
r = requests.get(INVENTORY_URL.format(steamid))
return r.json()['rgDescriptions']
def extract_information(descriptions):
for _, item in descriptions.items():
tags = {i['category']: i for i in item['tags']}
name = tags['market_name']
yield {
'name': name[name.find('|')+1:name.find('(')].strip(),
'market_name': name,
'market_hash_name': item['market_hash_name'],
'wear ': tags['Exterior']['name'],
'gun': tags['Weapon']['name'],
'stattrak': 'StatTrak' in tags['Quality']['name'],
'marketable': item['marketable'],
}
def get_prices(items):
for item in items:
if not item['marketable']:
continue
if item['wear'] not in wear_list:
continue
r = requests.get(
MARKET_URL,
params={
'appid': '730',
'currency': '2',
'market_hash_name': item['market_hash_name']
}
)
json_data = r.json()
try:
price = json_data['lowest_price']
except KeyError :
price = json_data['median_price']
item['price'] = price[-4:]
time.sleep(5)
yield item
if __name__ == '__main__':
inventory = get_inventory('76561198996231585')
item_information = extract_information(inventory)
items = get_prices(item_information)
for item in items:
print('{name}: {price}'.format(**item))
Traceback (most recent call last):
File "steam_price_item.py", line 59, in
for item in items:
File "steam_price_item.py", line 31, in get_prices
for item in items:
File "steam_price_item.py", line 19 , in extract_information
market_name = tags['name'],
KeyError: 'name'
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question