Pouknouki

loadInventoryFromSteam

Nov 7th, 2016
360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.59 KB | None | 0 0
  1.     def loadInventoryFromSteam(self, app, context):
  2.         import copy
  3.         TradingCards = []
  4.         result = None
  5.         more = True
  6.         start = 0
  7.         Inventory = {}
  8.         Descriptions = {}
  9.  
  10.         while more:
  11.             result = None
  12.             while result == None or unicode(result) == "null":
  13.                 result = downloadString("http://steamcommunity.com/profiles/" + unicode(self.SteamID64) + "/inventory/json/" + unicode(app) + "/" + unicode(context), {"start" : start}, {})
  14.             temp = json.loads(result)
  15.             resultJSON = copy.deepcopy(temp)
  16.  
  17.             #Unsucess is usually because of a private profile.
  18.             if resultJSON["success"] == False:
  19.                 return []
  20.  
  21.             #Load more items
  22.             if resultJSON["more"]:
  23.                 start = resultJSON["more_start"]
  24.             else:
  25.                 more = False
  26.  
  27.             descriptionsJSON = resultJSON["rgDescriptions"]
  28.             for desc in descriptionsJSON:
  29.                 Descriptions[descriptionsJSON[desc]["classid"]] = descriptionsJSON[desc]
  30.            
  31.             inventory = resultJSON["rgInventory"]
  32.             for item in inventory:
  33.                 for desc in Descriptions:
  34.                     if desc == inventory[item]["classid"]:
  35.                         Item = inventory[item]
  36.                         Description = Descriptions[desc]
  37.                         if Item["id"] in Inventory.keys():
  38.                             print("test")
  39.                         Inventory[Item["id"]] = SteamInventory.Item(Item["id"], context, Description["classid"], Description["instanceid"], Item["amount"], copy.deepcopy(Description))
  40.  
  41.         #Put the data we got to the property
  42.         if app not in self.Inventory.keys():
  43.             self.Inventory[app] = {}
  44.            
  45.         self.Inventory[app][context] = {}
  46.            
  47.         for item in Inventory:
  48.             self.Inventory[app][context][Inventory[item].itemid] = Inventory[item]
  49.  
  50.         return Inventory
Advertisement
Add Comment
Please, Sign In to add comment