steam.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # pylint: disable=C0303
  2. import requests
  3. import json
  4. SteamUN = "Marorin"
  5. key = '231E98D442E52B87110816C3D5114A1D'
  6. def gamesPulling(steamID,key):
  7. # Returns the JSON data from the Steam API based of one's
  8. # Steam ID number and returns a dictionary of gameids and minutes played.
  9. steaminfo = {
  10. 'key': key,
  11. 'steamid': steamID,
  12. 'format':'JSON',
  13. 'include_appinfo':'1'
  14. }
  15. r = requests.get('http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/', params=steaminfo)
  16. d = json.loads(r.content)
  17. return d['response']['games']
  18. def steamIDPulling(SteamUN,key):
  19. #Pulls out and returns the steam id number for use in steam queries.
  20. steaminfo = {'key': key,'vanityurl': SteamUN}
  21. a = requests.get('http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/', params=steaminfo)
  22. k = json.loads(a.content)
  23. SteamID = k['response']['steamid']
  24. return SteamID
  25. def steamlibrarypull(steamID, key):
  26. #Pulls out a CSV of Steam appids.
  27. steaminfo = {
  28. 'key': key,
  29. 'steamid': steamID,
  30. 'format':'JSON',
  31. 'include_appinfo':'1'
  32. }
  33. r = requests.get('http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/', params=steaminfo)
  34. d = json.loads(r.content)
  35. response = d['response']['games']
  36. games = {}
  37. for game in response:
  38. getprice = requests.get('http://store.steampowered.com/api/appdetails/?appids=%d&filters=price_overview&cc=us' % game['appid'])
  39. if getprice.status_code == 200:
  40. rjson = json.loads(getprice.text)
  41. # use the appid to fetch the value and convert to decimal
  42. # appid is numeric, cast to string to lookup the price
  43. try:
  44. price = rjson[str(game['appid'])]['data']['price_overview']['initial'] * .01
  45. except KeyError:
  46. pass
  47. games[game['name']] = {'price': price, 'appid': game['appid']}
  48. return games