瀏覽代碼

Adding bootstrap and pulling out relevant data

David Leonard 10 年之前
父節點
當前提交
4de2cd7e84

+ 3 - 1
hackathon_starter/hackathon/scripts/yelp.py

@@ -9,6 +9,7 @@ TOKEN = 'AWYVs7Vim7mwYyT1BLJA2xhNTs_vXLYS'
 TOKEN_SECRET = 'Rv4GrlYxYGhxUs14s0VBfk7JLJY'
 
 def requestData(location):
+    data = []
     url = 'http://api.yelp.com/v2/business/' + location
 
     consumer = oauth2.Consumer(CONSUMER_KEY, CONSUMER_SECRET)
@@ -28,5 +29,6 @@ def requestData(location):
     
     req = requests.get(signed_url)
     content = json.loads(req.content)
+    data.append(content)
 
-    return content
+    return data

+ 31 - 2
hackathon_starter/hackathon/templates/hackathon/yelp.html

@@ -10,8 +10,6 @@
     </style>
 
     <body>
-
-      {{ data }}
       <h1 class="text-center"> Yelp API </h1>
       <div class="container text-center">
         <form class="form-signin" id="login_form" method="post" action="/hackathon/yelp/">
@@ -25,5 +23,36 @@
         </form>
       </div>
 
+      	{% if data %}
+	      <div class="col-lg-12">
+	        <div class="table-responsive">
+	            <table class="table table-bordered table-hover table-striped tablesorter">
+	                <thead>
+	                <tr>
+	                <th class="header"> Name <i class="icon-sort"></i></th>
+	                <th class="header"> Snippet Text <i class="icon-sort"></i></th>
+	                <th class="header"> Open? <i class="icon-sort"></i></th>
+	                <th class="header"> Review Count <i class="icon-sort"></i></th>
+	                <th class="header"> URL <i class="icon-sort"></i></th>
+	                </tr>
+	            </thead>
+	            <tbody>
+
+	            {% for key in data %}
+	                <tr>
+	                    <td>{{ key.name }}</td>
+	                    <td>{{ key.snippet_text }}</td>
+	                    <td>{{ key.is_closed }}</td>
+	                    <td>{{ key.review_count }}</td>
+	                    <td>{{ key.url }}</td>
+	    			</tr>
+	            {% endfor %}
+
+	            </tbody>
+	            </table>
+	        </div>
+	      </div>
+	    {% endif %}
+
     </body>
 </html>