Author: simplet
Date: 2008-12-02 13:19:23 +0100 (Tue, 02 Dec 2008)
New Revision: 2982

Added:
   software_suite_v2/software/scripts/weather/
   software_suite_v2/software/scripts/weather/meteo.py
Log:
* weather script (google api)


Added: software_suite_v2/software/scripts/weather/meteo.py
===================================================================
--- software_suite_v2/software/scripts/weather/meteo.py                         
(rev 0)
+++ software_suite_v2/software/scripts/weather/meteo.py 2008-12-02 12:19:23 UTC 
(rev 2982)
@@ -0,0 +1,81 @@
+#!/usr/bin/python
+# -*- coding: latin1 -*-
+
+"""
+======================================================================
+
+ Weather script using Google Weather.
+
+ Usage: meteo.py "paris" <number of day for the forecast>
+
+ Simplet <simplet _at_ ptigeek _dot_ net>
+
+======================================================================
+"""
+
+
+__author__  = 'Simplet <simplet _at_ ptigeek _dot_ net>'
+__appname__ = 'Weather script'
+__version__ = '0.0.1'
+__date__    = '2008/12/02'
+__license__ = 'GPL'
+
+
+import urllib2
+from xml.dom import minidom
+import sys
+from tuxisalive.api import *
+
+
+def tux_speak(text):
+  print text
+  tux.tts.speak(text,"Julie",100)
+
+
+#def Far2Celsius(temp):
+# return str( ( int(temp)-32 ) *5 /9 )
+
+
+if len(sys.argv) < 2:
+  exit()
+
+if len(sys.argv) == 3:
+  iLimite = int(sys.argv[2])
+else:
+  iLimite = 5
+
+
+tux = TuxAPI('192.168.1.5', 270)
+tux.server.autoConnect(CLIENT_LEVEL_RESTRICTED, 'Meteo', 'NONE')
+tux.server.waitConnected(10.0)
+tux.dongle.waitConnected(10.0)
+tux.radio.waitConnected(10.0)
+if tux.access.waitAcquire(10.0, ACCESS_PRIORITY_NORMAL):
+
+   annonce = unicode("Météo pour " + sys.argv[1], 'utf8')
+   tux_speak(annonce.encode('latin1'))
+
+   the_url = "http://www.google.com/ig/api?weather="; + sys.argv[1].replace(' 
', '%20') + ",france&hl=fr"
+
+   req = urllib2.Request(the_url)
+   handle = urllib2.urlopen(req)
+
+   chaine = unicode(handle.read(), "iso-8859-1").encode('utf8')
+
+   xmldoc = minidom.parseString(chaine)
+
+   cpt = 0
+   for fc in xmldoc.getElementsByTagName('forecast_conditions'):
+      if cpt >= iLimite:
+        exit()
+      
tux_speak(fc.getElementsByTagName('day_of_week')[0].getAttribute('data').encode('latin1'))
+      tux_speak(str(fc.getElementsByTagName('low')[0].getAttribute('data')) + 
" degre le matin")
+      tux_speak(str(fc.getElementsByTagName('high')[0].getAttribute('data')) + 
" degre l'apret-midi")
+      
tux_speak(fc.getElementsByTagName('condition')[0].getAttribute('data').encode('latin1'))
+      cpt = cpt + 1
+
+tux.access.release()
+tux.server.disconnect()
+tux.destroy()
+
+


Property changes on: software_suite_v2/software/scripts/weather/meteo.py
___________________________________________________________________
Name: svn:executable
   + *


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to