I am new to python and the google app engine. I am trying to create this app that fetches feed from yahoo pipes and displays it using jinja2 templates. However I am getting a syntax error and I am not understanding the reason behind it.
import webapp2 from webapp2_extras import jinja2 import logging
import feedparser
import urllib
class BaseHandler(webapp2.RequestHandler):
@webapp2.cached_property
def jinja2(self):
return jinja2.get_jinja2(app=self.app)
def render_response(self, _template, **context):
rv = self.jinja2.render_template(_template, **context)
self.response.write(rv)
class MainHandler(BaseHandler):
def get(self):
feed = feedparser.parse("http://pipes.yahoo.com/pipes/pipe.run?_id=1nWYbWm82xGjQylL00qv4w&_render=rss&textinput1=dogs" )
feed = [{"link": item.link, "title":item.title, "description" : item.description} for item in feed["items"]
context = {"feed" : feed, "search" : "dogs"}
self.render_response('index.html', **context)
def post(self):
terms = self.request.get('search_term')
terms = urllib.quote(terms)
feed = feedparser.parse("http://pipes.yahoo.com/pipes/pipe.run?_id=1nWYbWm82xGjQylL00qv4w&_render=rss&textinput1=" + terms )
feed = [{"link": item.link, "title":item.title, "description" : item.description} for item in feed["items"]]
context = {"feed": feed, "search": terms}
self.render_response('index.html', **context)
app = webapp2.WSGIApplication([
('/', MainHandler)
], debug=True)
Here is the index.html file
<!DOCTYPE html>
<html>
<head>
<title>Byte 1 Tutoral</title>
</head>
<body>
<h1>Data Pipeline Project Byte 1 Example</h1>
<form action="search" method="POST">
Search Term: <input name="search_term" value={{search}}><br>
<input type="submit" value="Enter Search Term">
</form>
{% if search: %}
<p>Searching for {{search}}</p>
{% endif %}
<h2>Feed Contents</h2>
{% for item in feed %}
<a href="{{ item.link }}">{{ item.title }}</a><br>
{{item.description|safe}}
<br>
{% endfor %}
</body>
</html>
and this is the error that I am getting.
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 239, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 298, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\runtime\wsgi.py", line 84, in LoadObject
obj = __import__(path[0])
File "C:\googleapps\ykelkar-byte1\main.py", line 38
context = {"feed" : feed, "search" : "dogs"}
^
SyntaxError: invalid syntax
INFO 2014-01-16 23:15:25,845 module.py:612] default: "GET / HTTP/1.1" 500 -
Thanks.