Переглянути джерело

modify the getBlogInfo function and working on getTaggedInfo(), and modify the view

mk200789 10 роки тому
батько
коміт
8d2ba7a97f

+ 14 - 1
hackathon_starter/hackathon/scripts/tumblr.py

@@ -1,6 +1,8 @@
 import requests
 import simplejson as json
 import time 
+import collections
+import urllib
 
 blog_uri		= "http://api.tumblr.com/v2/blog/"
 user_uri		= "api.tumblr.com/v2/user/"
@@ -21,4 +23,15 @@ def getBlogInfo(user):
 	response = jsonlist['response']
 	blog = response['blog']
 	blog['updated'] = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(blog['updated']))
-	return meta, response, blog
+
+	return meta, response, blog
+
+def getTaggedInfo(tag):
+	tagged_uri = "http://api.tumblr.com/v2/tagged?tag="+tag+"&api_key="+consumer_key+"&limit=2"
+	req = requests.get(tagged_uri)
+	jsonlist = json.loads(req.content)
+	
+	meta = jsonlist['meta']
+	response = jsonlist['response'][0]
+	
+	return response

+ 28 - 5
hackathon_starter/hackathon/templates/hackathon/tumblr.html

@@ -2,18 +2,41 @@
 <html>
 <body>
 	{% include 'hackathon/base.html' %}
-	<div class="col-lg-12">
-		<h1> {{ title }} : User Blog Info </h1> 
+	<div class="col-md-6">
+		<h1 class="text-center"> {{ title }}</h1> 
 		<br>
 		<div class="table-responsive">
-			<table class="table">
+			<table class="table table-bordered">
+				<tr>
+					<th>Name</th>
+					<td>{{blogData.name}}</td>
+				</tr>
+				<tr>
+					<th>Posts</th>
+					<td>{{blogData.posts}}</td>				
+				</tr>
+				<tr>
+					<th>Blog title</th>
+					<td>{{blogData.title}}</td>				
+				</tr>
+				<tr>
+					<th>Last updated</th>
+					<td>{{blogData.updated}}</td>				
+				</tr>
+				<tr>
+					<th>Description</th>
+					<td>{{blogData.description}}</td>				
+				</tr>				
+			</table>
+			{{blogTag}}
+			<!--<table class="table">
 				{% for i,v in blogData.items %}
 				<tr>
 					<th>{{i}}</th>
 					<td>{{v}}</td>
 				</tr>
-				{% endfor %}
-			</table>
+				{% endfor %}		
+			</table>-->
 		</div>
 	</div>
 </body>

+ 5 - 4
hackathon_starter/hackathon/views.py

@@ -6,8 +6,8 @@ from django.contrib.auth import authenticate, login
 from django.http import HttpResponse, HttpResponseRedirect
 from scripts.steam import gamesPulling, steamIDPulling 
 from scripts.github import *
-from scripts.tumblr import getUserInfo as tumblrUserInfo
-from scripts.tumblr import getBlogInfo as tumblrBlogInfo
+from scripts.tumblr import *
+
 
 
 def index(request):
@@ -144,8 +144,9 @@ def github(request):
     return render(request, 'hackathon/github.html', { 'data': allData })
 
 def tumblr(request):
-    meta, response, blog = tumblrBlogInfo('david')
-    context = {'title': 'Tumblr Example', 'blogData': blog}
+    meta, response, blog = getBlogInfo('twitterthecomic')
+    tagged_blog = getTaggedInfo("obama")
+    context = {'title': 'Tumblr Example', 'blogData': blog, 'blogTag': tagged_blog}
     return render(request, 'hackathon/tumblr.html', context)
 
 def linkedin(request):