-
Notifications
You must be signed in to change notification settings - Fork 0
/
barrel.py
54 lines (36 loc) · 1.23 KB
/
barrel.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import urllib
import bitly
import webapp2
import jinja2
from google.appengine.api import users
from google.appengine.ext import ndb
JINJA_ENVIRONMENT = jinja2.Environment(
loader=jinja2.FileSystemLoader(os.path.dirname(__file__)),
extensions=['jinja2.ext.autoescape'],
autoescape=True)
class MainPage(webapp2.RequestHandler):
def get(self):
response = {}
template_values = {
'show_response': False
}
template = JINJA_ENVIRONMENT.get_template('index.html')
self.response.write(template.render(template_values))
class SearchPage(webapp2.RequestHandler):
def post(self):
user_input = {}
user_input['query'] = self.request.get('query')
user_input['location'] = self.request.get('location')
response = bitly.search(user_input)
template_values = {
'response': response,
'show_response': True,
'response_found': len(response['data']['results']) > 0
}
template = JINJA_ENVIRONMENT.get_template('index.html')
self.response.write(template.render(template_values))
application = webapp2.WSGIApplication([
('/', MainPage),
('/search.*', SearchPage),
], debug=True)