Download: NewsResults.py
Usage: <<NewsResults(portland+wifi)>>
Description: Display a list of 10 Google News search results sorted by date

   1 # Usage: <<NewsResults(portland+wifi)>>
   2 
   3 Dependencies = ["time"]
   4 
   5 from MoinMoin import util, wikiutil, config
   6 
   7 class rssWiki:
   8     def __init__(self, macro, text):
   9         self.macro = macro
  10         self.fmt = macro.formatter
  11         # google news search url. 10 items, sorted by date 
  12 	url = "http://news.google.com/news?hl=en&ned=&q=%s&ie=UTF-8&scoring=n&output=rss" % (text)
  13         import feedparser
  14         self.f = feedparser.parse(url)
  15         self.result = []
  16 
  17     def get_date(self, date):
  18         self.result.append(self.fmt.rawHTML(date+" - "))
  19 
  20     def get_link(self, link):
  21         self.result.append(self.fmt.url(on=1, href=link) + \
  22                            self.fmt.icon('www'))
  23 
  24     def get_entry_header(self, title):
  25         self.result.append(self.fmt.rawHTML(" "+title) + \
  26 			   self.fmt.url(on=0) + \
  27 			   self.fmt.rawHTML('<br>'))
  28 
  29     def get_entries(self):
  30         for entry in self.f.entries:
  31             if entry.has_key('date'):
  32                 self.get_date(entry.date)
  33             if entry.has_key('link'):
  34                 self.get_link(entry.link)
  35             if entry.has_key('title'):
  36                 self.get_entry_header(entry.title)
  37 
  38     def get_output(self):
  39 	self.get_entries()
  40         return ''.join(self.result)
  41 
  42 def execute(macro, text):
  43       rss = rssWiki(macro, text)
  44       return rss.get_output()
  45 
NewsResults.py

Macros/NewsResults (last edited 2008-05-20 08:32:49 by JasonMcArthur)