Prechádzať zdrojové kódy

Reforked and REadded mywork

Marco Quezada 10 rokov pred
rodič
commit
b7d2448953

+ 26 - 0
hackathon_starter/hackathon/scripts/SteamAPI.py

@@ -0,0 +1,26 @@
+import requests
+import json
+SteamUN = "Marorin"
+# steamID = SteamIDpulling(SteamUN)
+key = '231E98D442E52B87110816C3D5114A1D'
+
+def gamespulling(steamID,key):
+    # Returns the XML data from the Steam API based of one's Steam ID number and returns a dictionary of gameids and minutes played.
+    steaminfo = {'key': key, 'steamid': steamID,'format':'JSON','include_appinfo':'1'}
+    r = requests.get('http://api.steampowered.com/IPlayerService/GetOwnedGames/v0001/',params=steaminfo)  
+    d = json.loads(r.content)
+    # print d['response']['games']
+    # print r.json()
+    return d['response']['games']
+ 
+def steamIDpulling(SteamUN,key):
+    #Pulls out and returns the steam id number for use in steam queries.
+    steaminfo = {'key': key,'vanityurl': SteamUN}
+    a = requests.get('http://api.steampowered.com/ISteamUser/ResolveVanityURL/v0001/',params=steaminfo)
+    k = json.loads(a.content)
+    SteamID = k['response']['steamid']
+    print SteamID
+    return SteamID
+# steampulling(steamID)
+steamID = steamIDpulling(SteamUN, key)
+gamespulling(steamID,key)

+ 0 - 0
hackathon_starter/hackathon/scripts/__init__.py


+ 12 - 0
hackathon_starter/hackathon/templates/hackathon/SteamAPI.html

@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<body>
+<table>
+  <tr><th>Game ID</th><th>Game Name</th><th>Minutes Played</th></tr>
+  {% for game in game %}
+    {% comment %}  each game object is a dictionary with "appid", "name " and "playtime_forever" keys {% endcomment %}
+    <tr><td>{{ game.appid }}</td><td>{{game.name}} </td><td>{{ game.playtime_forever }}</td></tr>
+{% endfor %}
+</table>
+</body>
+</html>

+ 3 - 2
hackathon_starter/hackathon/urls.py

@@ -8,5 +8,6 @@ urlpatterns = patterns('',
     url(r'^register/$', views.register, name='register'),
     url(r'^login/$', views.user_login, name='login'),
     url(r'^logout/$', views.user_logout, name='logout'),
-    url(r'^api/$', views.api_examples, name='api')
-)
+    url(r'^api/$', views.api_examples, name='api'),
+    url(r'^SteamAPI/$',views.SteamAPI,name='steamAPI')
+)

+ 10 - 1
hackathon_starter/hackathon/views.py

@@ -4,7 +4,7 @@ from django.contrib.auth import logout
 from django.template import RequestContext, loader
 from django.contrib.auth import authenticate, login
 from django.http import HttpResponse, HttpResponseRedirect
-
+from scripts.SteamAPI import * 
 def index(request):
 	context = {'hello': 'world'}
 	return render(request, 'hackathon/index.html', context)
@@ -104,3 +104,12 @@ def user_logout(request):
 
     # Take the user back to the homepage.
     return HttpResponseRedirect('/hackathon/')
+
+def SteamAPI(request):
+    #Should link to test of Steam API example.
+    key = '231E98D442E52B87110816C3D5114A1D'
+    SteamUN = "Marorin"
+    steamID = steamIDpulling(SteamUN, key)
+    game = gamespulling(steamID, key)
+    return render(request,'hackathon/SteamAPI.html',{"game": game})
+