I have this code:
import jinja2
import webapp2
import os
from google.appengine.ext import db
import feedparser
from xml.dom import minidom
from google.appengine.api import memcache
template_dir = os.path.join(os.path.dirname(__file__), 'templates')
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir), autoescape = True)
class News(db.Model):
title = db.StringProperty(required=True)
description = db.StringProperty(required=True)
url = db.StringProperty(required=True)
imageurl = db.StringProperty(required=True)
feeds = [ 'https://news.google.co.in/news/section?cf=all&pz=1&ned=in&topic=e&ict=ln&output=rss' # Entertainment
'https://news.google.co.in/news/section?cf=all&pz=1&ned=in&topic=snc&ict=ln&output=rss' # Science
'https://news.google.co.in/news/section?cf=all&pz=1&ned=in&topic=s&ict=ln&output=rss' # Sports
'https://news.google.co.in/news/section?cf=all&pz=1&ned=in&topic=b&ict=ln&output=rss' # Business
'https://news.google.co.in/news/section?cf=all&pz=1&ned=in&topic=tc&ict=ln&output=rss' # Technology
]
def render_str(template, **params):
t = jinja_env.get_template(template)
return t.render(params)
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.write(feedparser.__file__)
self.response.write(render_str('mainpage.html'))
class Entertainment(webapp2.RequestHandler):
def get(self):
rssfeed = feedparser.parse(feeds[0])
self.response.write(rsfeed.entries[0].title)
self.response.write(rsfeed.entries[0].link)
self.response.write(rsfeed.entries[0].published)
self.response.write(rsfeed.entries[0].description)
app = webapp2.WSGIApplication([('/', MainPage),
('/entertainment', Entertainment)
], debug = True)
mainpage.html
has nothing except five <p></p>
tags with one of them hyperlinked to /entertainment
.
When I run it and click on the hyperlinked paragraph, I get this
AttributeError: 'module' object has no attribute 'parse'
I've followed this question, which is why I printed out the filepath in the get
of MainPage
.
My folder structure is :
templates
- mainpage.html
app.yaml
feedparser.py
newsapp.py
newsapp.pyc
When I ran it the first time, feedparser pointed to C:\Users\IBM_ADMIN\Downloads\7c\News Aggregator GAE\feedparser.pyc
. That was wrong, so I deleted the .pyc
file, and then it pointed to C:\Users\IBM_ADMIN\Downloads\7c\News Aggregator GAE\feedparser.py
. But it still gave the same error and the .pyc
file got generated again. I know it gets generated because I'm compiling the feedparser file, but why does the feedparser module point to that location? And how can I get around that error?