Author: duncan
Date: Fri Dec 22 16:42:30 2006
New Revision: 8793

Added:
   branches/rel-1/freevo/src/plugins/weather_update.py
      - copied, changed from r8785, 
/branches/rel-1/freevo/src/helpers/weather.py
Removed:
   branches/rel-1/freevo/src/helpers/weather.py

Log:
Moved to the plugins directory from helpers directory


Copied: branches/rel-1/freevo/src/plugins/weather_update.py (from r8785, 
/branches/rel-1/freevo/src/helpers/weather.py)
==============================================================================
--- /branches/rel-1/freevo/src/helpers/weather.py       (original)
+++ branches/rel-1/freevo/src/plugins/weather_update.py Fri Dec 22 16:42:30 2006
@@ -1,13 +1,18 @@
 # -*- coding: iso-8859-1 -*-
 # -----------------------------------------------------------------------
-# weather.py Freevo Weather Helper
+# weather.py Freevo Weather Plugin
 # -----------------------------------------------------------------------
 # $Id$
 #
 # Notes:
-#   Requires cron to call "freevo weather" to get updates. The weather.py
-#   plugin will grab new data if the cache is older than two hours, so
-#   run your cron job more often than that.
+#   To enable add the following to your local_conf.py
+#
+#   plugin.activate('weather_update')
+#   WEATHER_UPDATE_INTERVAL = 10
+#
+#   The WEATHER_UPDATE_INTERVAL is set in whole minutes.
+#   The weather plugin will grab new data if the cache is older than
+#   two hours, so set the update interval to more often than that.
 #
 # Todo:
 #
@@ -34,22 +39,31 @@
 
 import os
 import stat
-import urllib
+import time
 import config
 
-location = []
-dataurl = []
-WEATHER_DIR = os.path.join(config.SHARE_DIR, 'images', 'weather')
-for local in config.PLUGIN_WEATHER_LOCATIONS:
-    location = local[0]
-    dataurl = "http://www.msnbc.com/m/chnk/d/weather_d_src.asp?acid=%s"; % 
location
-    mapurl = "http://w3.weather.com/weather/map/%s?from=LAPmaps"; % location
-    cacheDir = '%s/weather_%s' % (config.FREEVO_CACHEDIR, location)
-    cacheFile = '%s/data' % (cacheDir)
-    mapFile = '%s/map' % (cacheDir)
+if hasattr(config, 'PLUGIN_WEATHER_LOCATIONS'):
+    while hasattr(config, 'WEATHER_UPDATE_INTERVAL'):
+        location = []
+        dataurl = []
+        WEATHER_DIR = os.path.join(config.SHARE_DIR, 'images', 'weather')
+        for local in config.PLUGIN_WEATHER_LOCATIONS:
+            location = local[0]
+            dataurl = 
'http://www.msnbc.com/m/chnk/d/weather_d_src.asp?acid=%s' % location
+            mapurl = 'http://w3.weather.com/weather/map/%s?from=LAPmaps' % 
location
+            cacheDir = '%s/weather_%s' % (config.FREEVO_CACHEDIR, location)
+            cacheFile = '%s/data' % (cacheDir)
+            mapFile = '%s/map' % (cacheDir)
 
-    if not os.path.isdir(cacheDir):
-        os.mkdir(cacheDir, 
stat.S_IMODE(os.stat(config.FREEVO_CACHEDIR)[stat.ST_MODE]))
+            if not os.path.isdir(cacheDir):
+                os.mkdir(cacheDir, 
stat.S_IMODE(os.stat(config.FREEVO_CACHEDIR)[stat.ST_MODE]))
 
-    os.system ('wget %s -O %s 2> /dev/null' % (dataurl, cacheFile))
-    os.system ('wget %s -O %s 2> /dev/null' % (mapurl, mapFile))
+            os.system ('wget %s -O %s 2> /dev/null' % (dataurl, cacheFile))
+            os.system ('wget %s -O %s 2> /dev/null' % (mapurl, mapFile))
+            if config.DEBUG == 1:
+                print 'Updated weather data for \"%s\"' % (location)
+            time.sleep(config.WEATHER_UPDATE_INTERVAL * 60)
+    else:
+        print 'WEATHER_UPDATE_INTERVAL not defined in local_conf.py'
+else:
+    print 'PLUGIN_WEATHER_LOCATIONS not defined in local_conf.py'

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog

Reply via email to