steam.py 1.0 KB

1234567891011121314151617181920212223242526272829
  1. '''This script contains methods belonging to the Steam web API
  2. that can collect information based on an user's gaming library.'''
  3. import requests
  4. import json
  5. def gamespulling(steamid, apikey):
  6. '''Returns the JSON data from the Steam API based of one's
  7. Steam ID number and returns a dictionary of
  8. gameids and minutes played.'''
  9. steaminfo = {
  10. 'key': apikey,
  11. 'steamid': steamid,
  12. 'format':'JSON',
  13. 'include_appinfo':'1'
  14. }
  15. apiurl = 'http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/'
  16. req = requests.get(apiurl, params=steaminfo)
  17. data = json.loads(req.content)
  18. return data['response']['games']
  19. def steamidpulling(steamun, apikey):
  20. '''Pulls out and returns the steam id number for use in steam queries.'''
  21. steaminfo = {'key': apikey, 'vanityurl': steamun}
  22. apiurl = 'http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/'
  23. req = requests.get(apiurl, params=steaminfo)
  24. data = json.loads(req.content)
  25. steamid = data['response']['steamid']
  26. return steamid