Attachment 'NewsResults.py'

Download

   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 

New Attachment

File to upload
Rename to
Overwrite existing attachment of same name
Name our hockey team

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.