So how about a script that actually does something?
import requests
import json
APIkey = 'yourKey'
#getTornItems
itemsURL = 'https://api.torn.com/torn/?selections=items&key=%s'%(APIkey)
TornItems = json.loads(requests.get(itemsURL).text)['items']
#Search for item
itemx = input("Prices on...")
itemx = itemx.title()
itemID = str()
while len(itemID) for key in TornItems.keys():
if TornItems[key]['name'] == itemx:
itemID = key
if len(itemID) itemx = input("Nope Re-Enter...")
itemx = itemx.title()
#getBazaarPrices
bazaarURL = 'http://api.torn.com/market/%s?selections=bazaar&key=%s'%(itemID,APIkey)
BazaarPrices = json.loads(requests.get(bazaarURL).text)['bazaar']
print(itemx, 'ID:', itemID)
print()
print()
#Print Prices
playerID = str()
for randID in sorted(BazaarPrices, key=lambda x: (BazaarPrices[x]['cost'], BazaarPrices[x]['quantity'])):
print(randID )
print(' Quantity:','{:,}'.format(BazaarPrices[randID ]['quantity']))
print(' Cost: ','{:,}'.format(BazaarPrices[randID ]['cost']))
print()
print()
input("Press Enter to quit...")
The
while loop is checking the user's input against the full list of items from the Torn section of the api after putting the input in title case. If a match is found then the ID of that item is set as
itemID. That item ID is then passed to the item market section of the api with the selection bazaar.
The ID's you see printed for bazaars are
NOT player IDs or bazaar IDs or anything like that. You are
not intended to be able to tell who the seller is, just the existence of the listing.
[image: i.imgur.com][image: i.imgur.com] A Few Final Notes
All of the screen shots above were produced by pushing f5 in the editor. If you try to double click on a .py file to run it that will work but the output will flash across the screen too fast for you to read it. An easy way to make the output stay on screen long enough to be read is to put input("Press Enter to quit...") at the end of your code. This is used to get text input from the user, but we don't have to do anything with that input and it provides a simple pause. The string inside is simply the prompt to the user for what input is expected. For our purposes here it could just as well be left blank input().
Time stamps in the API are in
Unix time Python datetime reference: https://docs.python.org/3/library/datetime.html
A handy converter: https://www.epochconverter.com/
If you are having trouble running python scripts by double clicking, make sure the program set to run them is
C:WINDOWSpy.exe[image: i.imgur.com]