예제 #1
0
 def post(self):
     key = self.request.get('key')
     feed = NewsFeed.get_by_key_name(key)
     # FIXME check if feed was retrieved
     result = urlfetch.fetch(feed.url)
     if result.status_code == 200:
         rssfeed = feedparser.parse(result.content)
         for i in rssfeed.entries:
             item = NewsItem(key_name=i.guid)
             item.url = i.link
             item.title = i.title
             item.text = i.summary
             item.date = datetime.datetime(*i.date_parsed[:6])
             item.orderdate = datetime.datetime(*i.date_parsed[:6])
             item.source = feed
             item.put()
         feed.last_fetch = datetime.datetime.now() 
         feed.put() 
         taskqueue.add(queue_name='fetch-news-queue', url='/admin/feeds/fetch/', params={'key':feed.key})
         self.response.out.write('feed pulled')
     else:  
         self.error(500)
예제 #2
0
    def get(self): 
        url = settings.YAHOO_PIPE % 'rss'  
        result = urlfetch.fetch(url) 
        if result.status_code == 200:
            feed = feedparser.parse(result.content) 
            for i in feed.entries:  
                item = NewsItem(key_name=i.guid) 
                item.url = i.link
                item.title = i.title 
                item.text = i.summary
                item.date = datetime.datetime(*i.date_parsed[:6])
                item.orderdate = datetime.datetime(*i.date_parsed[:6])
                item.put() 

            items = db.GqlQuery("SELECT * FROM NewsItem ORDER BY orderdate DESC LIMIT 100")
 
            context = {'news':items }
            #context = add_user_to_context(context)
            self.response.out.write(
               template.render(tmpl('templates/news2.html'),
               context ))
        else: 
            self.response.out.write('err')