Просмотр исходного кода

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

Updated requirements.txt + included tumblr view
David Leonard 10 лет назад
Родитель
Сommit
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 json
-SteamUN = "Marorin"
 
+SteamUN = "Marorin"
 key = '231E98D442E52B87110816C3D5114A1D'
 
 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)
     return d['response']['games']
  
@@ -19,6 +27,3 @@ def steamIDPulling(SteamUN,key):
     SteamID = k['response']['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>
-  <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>
     <nav class="navbar navbar-default" role="navigation">
@@ -54,4 +54,5 @@
         </div><!-- /.navbar-collapse -->
       </div><!-- /.container-fluid -->
     </nav>
-  </body>
+  </body>
+</html>

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

@@ -2,6 +2,38 @@
 <html>
 <body>
 	{% 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>
 </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.http import HttpResponse, HttpResponseRedirect
 from scripts.steam import gamesPulling, steamIDPulling 
+from scripts.github import getUserData
 
 
 def index(request):
@@ -116,8 +117,8 @@ def steam(request):
     return render(request,'hackathon/steam.html', {"game": game })
 
 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):
     context = {'title': 'Tumblr Example'}

+ 1 - 0
requirements.txt

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