Explorar o código

Merged in mk200789/django-hackathon-starter (pull request #11)

Updated requirements.txt + included tumblr view
David Leonard %!s(int64=10) %!d(string=hai) anos
pai
achega
ee373a8037

+ 35 - 0
hackathon_starter/hackathon/scripts/github.py

@@ -0,0 +1,35 @@
+'''
+Module github.py contains a handful of methods
+for interacting with Github data.
+'''
+
+import requests
+import simplejson as json
+
+########################
+# GITHUB API CONSTANTS #
+########################
+
+API_BASE_URL = 'https://api.github.com/'
+API_USERS_URL = API_BASE_URL + 'users/DrkSephy'
+
+def getUserData():
+	req = requests.get(API_USERS_URL)
+	jsonList = []
+	jsonList.append(json.loads(req.content))
+	parsedData = []
+	userData = {}
+	for data in jsonList: 
+		userData['name'] = data['name']
+		userData['blog'] = data['blog']
+		userData['email'] = data['email']
+		userData['public_gists'] = data['public_gists']
+		userData['public_repos'] = data['public_repos']
+		userData['avatar_url'] = data['avatar_url']
+		userData['followers'] = data['followers']
+		userData['following'] = data['following']
+	parsedData.append(userData)
+	return parsedData
+	
+	
+	

+ 12 - 7
hackathon_starter/hackathon/scripts/steam.py

@@ -1,13 +1,21 @@
+# pylint: disable=C0303
+
 import requests
 import requests
 import json
 import json
-SteamUN = "Marorin"
 
 
+SteamUN = "Marorin"
 key = '231E98D442E52B87110816C3D5114A1D'
 key = '231E98D442E52B87110816C3D5114A1D'
 
 
 def gamesPulling(steamID,key):
 def gamesPulling(steamID,key):
-    # Returns the JSON 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)  
+    # Returns the JSON 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)
     d = json.loads(r.content)
     return d['response']['games']
     return d['response']['games']
  
  
@@ -19,6 +27,3 @@ def steamIDPulling(SteamUN,key):
     SteamID = k['response']['steamid']
     SteamID = k['response']['steamid']
     
     
     return SteamID
     return SteamID
-# steampulling(steamID)
-steamID = steamIDPulling(SteamUN, key)
-gamesPulling(steamID,key)

+ 12 - 11
hackathon_starter/hackathon/templates/hackathon/base.html

@@ -1,14 +1,14 @@
 <!DOCTYPE html>
 <!DOCTYPE html>
-  <html lang="en">
-    <head>
-      <title> Django Hackathon Starter </title>
-      <script src="/static/bower_components/jquery/dist/jquery.js"></script>
-      <script type="text/javascript" src="/static/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
-      
-      
-      <link rel="stylesheet" href="/static/bower_components/bootstrap/dist/css/bootstrap.min.css">
-      <link rel="stylesheet" href="/static/bower_components/bootstrap/dist/css/bootstrap-theme.min.css">
-    </head>
+<html lang="en">
+  <head>
+    <title> Django Hackathon Starter </title>
+    <script src="/static/bower_components/jquery/dist/jquery.js"></script>
+    <script type="text/javascript" src="/static/bower_components/bootstrap/dist/js/bootstrap.min.js"></script>
+    
+    
+    <link rel="stylesheet" href="/static/bower_components/bootstrap/dist/css/bootstrap.min.css">
+    <link rel="stylesheet" href="/static/bower_components/bootstrap/dist/css/bootstrap-theme.min.css">
+  </head>
     
     
   <body>
   <body>
     <nav class="navbar navbar-default" role="navigation">
     <nav class="navbar navbar-default" role="navigation">
@@ -54,4 +54,5 @@
         </div><!-- /.navbar-collapse -->
         </div><!-- /.navbar-collapse -->
       </div><!-- /.container-fluid -->
       </div><!-- /.container-fluid -->
     </nav>
     </nav>
-  </body>
+  </body>
+</html>

+ 33 - 1
hackathon_starter/hackathon/templates/hackathon/github.html

@@ -2,6 +2,38 @@
 <html>
 <html>
 <body>
 <body>
 	{% include 'hackathon/base.html' %}
 	{% include 'hackathon/base.html' %}
-	<h1> {{ title }} </h1> 
+
+	<div class="col-lg-12">
+    <div class="table-responsive">
+        <table class="table table-bordered table-hover table-striped tablesorter">
+            <thead>
+            <tr>
+            <th class="header"> Username <i class="icon-sort"></i></th>
+            <th class="header"> Blog <i class="icon-sort"></i></th>
+            <th class="header"> Public Repos <i class="icon-sort"></i></th>
+            <th class="header"> Public Gists <i class="icon-sort"></i></th>
+            <th class="header"> Email <i class="icon-sort"></i></th>
+            <th class="header"> Followers <i class="icon-sort"></i></th>
+            <th class="header"> Following <i class="icon-sort"></i></th>
+            </tr>
+        </thead>
+        <tbody>
+
+        {% for key in data %}
+            <tr>
+                <td>{{ key.name }}</td>
+                <td>{{ key.blog }}</td>
+                <td>{{ key.public_repos }}</td>
+                <td>{{ key.public_gists }}</td>
+                <td>{{ key.email }}</td>
+                <td>{{ key.followers }}</td>
+                <td>{{ key.following }}</td>
+			</tr>
+        {% endfor %}
+
+        </tbody>
+        </table>
+    </div>
+</div>
 </body>
 </body>
 </html>
 </html>

+ 3 - 2
hackathon_starter/hackathon/views.py

@@ -5,6 +5,7 @@ from django.template import RequestContext, loader
 from django.contrib.auth import authenticate, login
 from django.contrib.auth import authenticate, login
 from django.http import HttpResponse, HttpResponseRedirect
 from django.http import HttpResponse, HttpResponseRedirect
 from scripts.steam import gamesPulling, steamIDPulling 
 from scripts.steam import gamesPulling, steamIDPulling 
+from scripts.github import getUserData
 
 
 
 
 def index(request):
 def index(request):
@@ -116,8 +117,8 @@ def steam(request):
     return render(request,'hackathon/steam.html', {"game": game })
     return render(request,'hackathon/steam.html', {"game": game })
 
 
 def github(request):
 def github(request):
-    context = {'title': 'Github Example'}
-    return render(request, 'hackathon/github.html', context)
+    userData = getUserData()
+    return render(request, 'hackathon/github.html', { 'data': userData })
 
 
 def tumblr(request):
 def tumblr(request):
     context = {'title': 'Tumblr Example'}
     context = {'title': 'Tumblr Example'}

+ 1 - 0
requirements.txt

@@ -11,6 +11,7 @@ nose==1.3.4
 pylint==1.4.3
 pylint==1.4.3
 python-openid==2.2.5
 python-openid==2.2.5
 requests==2.6.0
 requests==2.6.0
+simplejson==3.6.5
 six==1.9.0
 six==1.9.0
 wsgiref==0.1.2
 wsgiref==0.1.2
 pytumblr==0.0.6
 pytumblr==0.0.6