Commits

Anonymous committed 1003dc9

Adding MoinMoin macro for getting the weather from Yahoo

  • Participants
  • Parent commits b783dec

Comments (0)

Files changed (1)

7oars-moin/Weather.py

+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2009 John Paulett (john -at- 7oars.com)
+# All rights reserved.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution.
+
+"""MoinMoin macro for getting the current weather from the Yahoo! forecast
+API
+
+Installation:
+  Copy Weather.py into $INSTANCE/data/plugin/macro 
+
+Usage:
+  <<<Weather(zipcode or locationid)>>
+
+  For more information about the acceptable parameters,
+  see http://developer.yahoo.com/weather/
+
+Example:
+  <<<Weather(19104)>>>
+
+"""
+
+from MoinMoin import wikiutil
+
+def macro_Weather(macro, location):
+    import feedparser    
+    f = feedparser.parse('http://weather.yahooapis.com/forecastrss?p=%s' % location)
+    try:
+        result = f.entries[0].summary
+    except:
+        # catch any IndexError or KeyErrors
+        result = 'Could not find weather information for %s' % location
+    return macro.formatter.rawHTML(result)