SEARCH

Enter your search query in the box above ^, or use the forum search tool.

You are not logged in.

#1 2009-01-01 17:47:41

sheri
#! CrunchBanger
Registered: 2008-11-26
Posts: 117

Openbox weather pipe menu

3156891942_19d442f85d_o.png

Just found it on the Arch Linux forums: http://bbs.archlinux.org/viewtopic.php?id=43432

Works like a charm. smile

Offline

Be excellent to each other!

#2 2009-01-01 18:03:24

corenominal
root
From: Lincoln, UK
Registered: 2008-11-20
Posts: 4,888
Website

Re: Openbox weather pipe menu

Whoa, very nice! Thank you for sharing. smile

Offline

#3 2009-01-01 18:42:49

jasonwert
Member
From: Traverse City, Michigan
Registered: 2008-12-18
Posts: 36
Website

Re: Openbox weather pipe menu

Very cool! I need that. Thanks for the link.


Give A Monkey A Brain and He'll Swear He's the Center of the Universe

Offline

#4 2009-01-01 19:59:02

kestrel
Species: F. sparverius
From: Moscow, Idaho
Registered: 2008-11-29
Posts: 170
Website

Re: Openbox weather pipe menu

Thanks Sheri. I heard good things about that Arch Linux, I'll have to watch their forums.

Sheri, how did you get a screen shot of the menu? Every time I take a screen shot the menu disappears before the screen is captured.


My web activities: Etsy Shop | Facebook | Blog

Offline

#5 2009-01-01 20:12:19

rizzo
#! wanderer
From: ~/
Registered: 2008-11-25
Posts: 5,109

Re: Openbox weather pipe menu

Thanks for sharing this Sheri, very cool smile

kestrel, use the delayed screenshot option from the Graphics menu (5 or 10 secs). Choose it, then open the menu.

Offline

#6 2009-01-01 20:29:36

kestrel
Species: F. sparverius
From: Moscow, Idaho
Registered: 2008-11-29
Posts: 170
Website

Re: Openbox weather pipe menu

Thanks for the info on the screen shot delay. I heard that before but why can't I remember it?? Anyways' this is what I was trying to post. Sheri and I are having about the same weather.

72f0c46772b54e263d3b3438457c2.png


My web activities: Etsy Shop | Facebook | Blog

Offline

#7 2009-01-01 22:54:27

michaelramm
The Inquisitor
From: Northport, AL USA
Registered: 2008-11-30
Posts: 175
Website

Re: Openbox weather pipe menu

kestrel wrote:

Thanks Sheri. I heard good things about that Arch Linux, I'll have to watch their forums.

Their community is pretty great, and there are a LOT of openbox users there. I go there every so often to see what they are up to.

Thanks Sheri, that is a GREAT addition to make.

Michael


The 1-Man IT Department | Ubuntu User #16666 | Linux User #451972
My Social Nets: Identi.ca | twitter | friendfeed
Crunchbangin' and Loving Every Minute of IT!

Offline

#8 2009-04-29 03:15:47

rfquerin
Inkscape Ninja
From: Beeton, Ontario, Canada
Registered: 2009-01-05
Posts: 383
Website

Re: Openbox weather pipe menu

I finally got around to adding this script and entry to my openbox menu. When I first installed it, I made sure to change the commented portions so that it would show the Celsius data rather than the Fahrenheit (we're all metric-i-fied up here wink ). Anyway, I noticed that this only changed the 'current conditions' portion to metric, but the remaining high and low values for the next few days were funky. While it was showing a nice 'C' symbol, the values were obviously still metric (if it really was going to be 63C tomorrow there was NO way I was going to work! smile ).

So after gazing at the python script for a while trying to rassle back up my meager python skills, I decided to take a look at the XML file it was getting from Google and lo and behold Google was not providing consistently metric data. Notice the high and low values in the forecast_condition portion compared to the current conditions in this snippet from the xml:

<xml_api_reply version="1">
−
<weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0">
−
<forecast_information>
<city data="New Tecumseth, ON"/>
<postal_code data="alliston"/>
<latitude_e6 data=""/>
<longitude_e6 data=""/>
<forecast_date data="2009-04-28"/>
<current_date_time data="2009-04-29 02:41:39 +0000"/>
<unit_system data="US"/>
</forecast_information>
−
<current_conditions>
<condition data="Partly Cloudy"/>
<temp_f data="34"/>
<temp_c data="1"/>
<humidity data="Humidity: 100%"/>
<icon data="/ig/images/weather/partly_cloudy.png"/>
<wind_condition data="Wind: N at 2 mph"/>
</current_conditions>
−
<forecast_conditions>
<day_of_week data="Tue"/>
<low data="40"/>
<high data="64"/>
<icon data="/ig/images/weather/chance_of_rain.png"/>
<condition data="Scattered Showers"/>
</forecast_conditions>

So I made a slight modification to the script to do the conversion on the high and low values myself. And wonder of wonders it appears to work! smile Here's the modified script. I don't know if this is a problem for anybody else running this thing with metric values, but it might be of use to someone. I've commented out the two lines I changed but left them in there for reference:

#!/usr/bin/python

import sys
import urllib
from string import maketrans
#from xml.sax import make_parser, handler
from xml.sax import handler, parseString
class ElementProcesser(handler.ContentHandler):
    
    def startElement(self, name, attrs):
        
        if name == "city":
            print "<separator label='" + attrs["data"] + "' />"
        elif name == "current_conditions":
            print "<separator label='Current conditions' />"
        elif name == "condition":
            print "<item label='Weather: " + attrs["data"] + "' />"
        elif name == "humidity":
            print "<item label='" + attrs["data"] + "' />"
        elif name == "wind_condition":
            print "<item label='" + attrs["data"] + "' />"
        elif name == "day_of_week":
            print "<separator label='" + self.getDayOfWeek(attrs["data"]) + "' />"
            
        #Celsius
        elif name == "temp_c":
            print "<item label='Temperature " + attrs["data"] + " C' />"
        elif name == "low":
            value = (int(attrs["data"])-32)*5/9
            print "<item label='Minimum " + str(value) + " C' />"
           # print "<item label='Minimum " + attrs["data"] + " C' />"
        elif name == "high":
            value = (int(attrs["data"])-32)*5/9
            print "<item label='Maximum " + str(value) + " C' />"
           # print "<item label='Maximum " + attrs["data"] + " C' />"
           
        
        #Fahrenheit
        #elif name == "temp_f":
            #print "<item label='Temperature " + attrs["data"] + " F' />"
        #elif name == "low":
            #print "<item label='Minimun " + attrs["data"] + " F' />"
        #elif name == "high":
            #print "<item label='Maximun " + attrs["data"] + " F' />"
        
        
    def endElement(self, name):
        
        if name == "current_conditions":
            print "<separator label='Forecast' />"
        
    
    def startDocument(self):
        print '<openbox_pipe_menu>'
    
    def endDocument(self):
        print '</openbox_pipe_menu>'
    
    def getDayOfWeek(self,day):
        
        #English
        if day == "Mon":
            return "Monday"
        elif day == "Tue":
            return "Tuesday"
        elif day == "Wed":
            return "Wednesday"
        elif day == "Thu":
            return "Thursday"
        elif day == "Sat":
            return "Saturday"
        elif day == "Sun":
            return "Sunday"
        
        else:
            return day

# You should use your local version of google to have the messages in your language and metric system
f = urllib.urlopen("http://www.google.ca/ig/api?weather="+sys.argv[1])
xml = f.read()
f.close()

#Avoid problems with non english characters
trans=maketrans("\xe1\xe9\xed\xf3\xfa","aeiou")
xml = xml.translate(trans)

#parser.parse("http://www.google.es/ig/api?weather="+sys.argv[1])
parseString(xml,ElementProcesser())

Offline

#9 2009-05-02 13:32:54

Nicky
#! CrunchBanger
From: Paris (France)
Registered: 2009-04-05
Posts: 163

Re: Openbox weather pipe menu

I have a problem with this script, but I don't know what.

The script I use is the original one from archlinux forum, that I modified a little to use google.fr

#!/usr/bin/python

import sys
import urllib
from string import maketrans
#from xml.sax import make_parser, handler
from xml.sax import handler, parseString
class ElementProcesser(handler.ContentHandler):
    
    def startElement(self, name, attrs):
        
        if name == "city":
            print "<separator label='" + attrs["data"] + "' />"
        elif name == "current_conditions":
            print "<separator label='Current condidtions' />"
        elif name == "condition":
            print "<item label='Weather: " + attrs["data"] + "' />"
        elif name == "humidity":
            print "<item label='" + attrs["data"] + "' />"
        elif name == "wind_condition":
            print "<item label='" + attrs["data"] + "' />"
        elif name == "day_of_week":
            print "<separator label='" + self.getDayOfWeek(attrs["data"]) + "' />"
            
        #Celsius
        elif name == "temp_c":
            print "<item label='Temperature " + attrs["data"] + " C' />"
        elif name == "low":
            print "<item label='Minimun " + attrs["data"] + " C' />"
        elif name == "high":
            print "<item label='Maximun " + attrs["data"] + " C' />"
        
        #Fahrenheit
        #elif name == "temp_f":
            #print "<item label='Temperature " + attrs["data"] + " F' />"
        #elif name == "low":
            #print "<item label='Minimun " + attrs["data"] + " F' />"
        #elif name == "high":
            #print "<item label='Maximun " + attrs["data"] + " F' />"
        
        
    def endElement(self, name):
        
        if name == "current_conditions":
            print "<separator label='Forecast' />"
        
    
    def startDocument(self):
        print '<openbox_pipe_menu>'
    
    def endDocument(self):
        print '</openbox_pipe_menu>'
    
    def getDayOfWeek(self,day):
        
        #Francais
        if day == "lun.":
            return "Lundi"
        elif day == "mar.":
            return "Mardi"
        elif day == "mer.":
            return "Mercredi"
        elif day == "jeu.":
            return "Jeudi"
        elif day == "ven.":
            return "Vendredi"
        elif day == "sam.":
            return "Samedi"
        elif day == "dim.":
            return "Dimanche"
        
        else:
            return day

# You should use your local version of google to have the messages in your language and metric system
f = urllib.urlopen("http://www.google.fr/ig/api?weather=paris")
xml = f.read()
f.close()

#Avoid problems with non english characters
trans=maketrans("\xe1\xe9\xed\xf3\xfa","aeiou")
xml = xml.translate(trans)

#parser.parse("http://www.google.es/ig/api?weather="+sys.argv[1])
parseString(xml,ElementProcesser())

I modified also the line 76 to simplify for the moment as it didn't work anyway:
f = urllib.urlopen("http://www.google.fr/ig/api?weather=paris")

As the menu didn't work I tried to launch the script in terminal and that's what it makes.

nicky@nicky-eee:~/scripts$ python meteo
<openbox_pipe_menu>
<separator label='Paris, IDF' />
<separator label='Current condidtions' />
<item label='Weather: Nuageux dans l'ensemble' />
<item label='Temperature 17 C' />
<item label='Humidite : 68%' />
Traceback (most recent call last):
  File "meteo", line 85, in <module>
    parseString(xml,ElementProcesser())
  File "/usr/lib/python2.5/xml/sax/__init__.py", line 49, in parseString
    parser.parse(inpsrc)
  File "/usr/lib/python2.5/xml/sax/expatreader.py", line 107, in parse
    xmlreader.IncrementalParser.parse(self, source)
  File "/usr/lib/python2.5/xml/sax/xmlreader.py", line 123, in parse
    self.feed(buffer)
  File "/usr/lib/python2.5/xml/sax/expatreader.py", line 211, in feed
    self._err_handler.fatalError(exc)
  File "/usr/lib/python2.5/xml/sax/handler.py", line 38, in fatalError
    raise exception
xml.sax._exceptions.SAXParseException: <unknown>:1:610: not well-formed (invalid token)
  

The beginning looks normal, but after I don't understand what is the problem and what can cause the fatal error big_smile

if somebody see the problem, thanks in advance.

Last edited by Nicky (2009-05-02 13:34:01)

Offline

#10 2009-05-02 14:08:21

Yogi
#! Member
From: France
Registered: 2009-03-25
Posts: 57

Re: Openbox weather pipe menu

Hi, chances are the accentuated characters make the script go wrong. Someone else (another of us frenchbanged) on this forum solved it, don't remember who...


Asus EeePC 901A (16Gb SSD) - Waldorf
old Toshiba laptop(Celeron 1,5GHz/20Go/512Mo) - Statler

Offline

#11 2009-05-02 14:55:49

Nicky
#! CrunchBanger
From: Paris (France)
Registered: 2009-04-05
Posts: 163

Re: Openbox weather pipe menu

Ah, maybe it is the matter neutral
If I look in the terminal answer the script succeeds with the line humidity " when the google page gives "humidité".

I will search on the forum if I found the other frenchie who fix the problem big_smile

Offline

#12 2009-05-02 15:20:26

Nicky
#! CrunchBanger
From: Paris (France)
Registered: 2009-04-05
Posts: 163

Re: Openbox weather pipe menu

Ok, I found the topic:

http://crunchbanglinux.org/forums/topic … rse-error/

And effectively it works when I call the script in terminal. In my openbox menu it makes nothing but I will find wink

Offline

#13 2009-05-03 10:55:57

Nicky
#! CrunchBanger
From: Paris (France)
Registered: 2009-04-05
Posts: 163

Re: Openbox weather pipe menu

In fact I don't find,

When I launch the script in terminal it looks great:

nicky@nicky-eee:~/scripts$ python meteo
<openbox_pipe_menu>
<separator label='Paris, IDF' />
<separator label='Conditions actuelles' />
<item label='Temps: Nuageux dans l'ensemble' />
<item label='Temperature 13 C' />
<item label='Humidite : 67%' />
<item label='Vent : NO a 5 km/h' />
<separator label='Previsions' />
<separator label='Dimanche' />
<item label='Minimun 6 C' />
<item label='Maximun 16 C' />
<item label='Temps: Nuageux dans l'ensemble' />
<separator label='Lundi' />
<item label='Minimun 7 C' />
<item label='Maximun 16 C' />
<item label='Temps: Couverture nuageuse partielle' />
<separator label='Mardi' />
<item label='Minimun 8 C' />
<item label='Maximun 18 C' />
<item label='Temps: Nuageux dans l'ensemble' />
<separator label='Mercredi' />
<item label='Minimun 8 C' />
<item label='Maximun 19 C' />
<item label='Temps: Nuageux' />
</openbox_pipe_menu>

when I launch it from the obmenu it doesn't work, nothing appear.

If I copy the result of the terminal directly in a menu it works (the only problems are the  '  that are used in french and cut some lines,  but it print something and globally the menu works).

the line used to launch the menu seems ok but maybe I forget something.
<menu execute="python ~/scripts/meteo" id="weather" label="Weather"/>

And the script meteo

#!/usr/bin/python

import sys
import urllib
from string import maketrans
#from xml.sax import make_parser, handler
from xml.sax import handler, parseString
class ElementProcesser(handler.ContentHandler):
    
    def startElement(self, name, attrs):
        
        if name == "city":
            print "<separator label='" + attrs["data"] + "' />"
        elif name == "current_conditions":
            print "<separator label='Conditions actuelles' />"
        elif name == "condition":
            print "<item label='Temps: " + attrs["data"] + "' />"
        elif name == "humidity":
            print "<item label='" + attrs["data"] + "' />"
        elif name == "wind_condition":
            print "<item label='" + attrs["data"] + "' />"
        elif name == "day_of_week":
            print "<separator label='" + self.getDayOfWeek(attrs["data"]) + "' />"
            
        #Celsius
        elif name == "temp_c":
            print "<item label='Temperature " + attrs["data"] + " C' />"
        elif name == "low":
            print "<item label='Minimun " + attrs["data"] + " C' />"
        elif name == "high":
            print "<item label='Maximun " + attrs["data"] + " C' />"
        
        #Fahrenheit
        #elif name == "temp_f":
            #print "<item label='Temperature " + attrs["data"] + " F' />"
        #elif name == "low":
            #print "<item label='Minimun " + attrs["data"] + " F' />"
        #elif name == "high":
            #print "<item label='Maximun " + attrs["data"] + " F' />"
        
        
    def endElement(self, name):
        
        if name == "current_conditions":
            print "<separator label='Previsions' />"
        
    
    def startDocument(self):
        print "<openbox_pipe_menu>"
    
    def endDocument(self):
        print "</openbox_pipe_menu>"
    
    def getDayOfWeek(self,day):
        
        #Francais
        if day == "lun.":
            return "Lundi"
        elif day == "mar.":
            return "Mardi"
        elif day == "mer.":
            return "Mercredi"
        elif day == "jeu.":
            return "Jeudi"
        elif day == "ven.":
            return "Vendredi"
        elif day == "sam.":
            return "Samedi"
        elif day == "dim.":
            return "Dimanche"
        
        else:
            return day

# You should use your local version of google to have the messages in your language and metric system
f = urllib.urlopen("http://www.google.fr/ig/api?weather=paris")
xml = f.read()
f.close()

#Avoid problems with non english characters
trans=maketrans("\xe1\xe9\xed\xf3\xfa\xe0","aeioua")
xml = xml.translate(trans)

#parser.parse("http://www.google.es/ig/api?weather="+sys.argv[1])
parseString(xml,ElementProcesser())

If somebody see the mistake...

Offline

#14 2009-05-03 11:38:15

rfquerin
Inkscape Ninja
From: Beeton, Ontario, Canada
Registered: 2009-01-05
Posts: 383
Website

Re: Openbox weather pipe menu

I may be mistaken, but don't you have to specify your city name as a parameter when you launch the script? So for instance my line in menu.xml is:

<menu id="pipe-weather" label="Weather" execute="python ~/.config/openbox/scripts/gweather.py alliston" />

Note that the order of things is a little different from yours (not a big deal I don't think) but note the town name "alliston" right after the script name.

Offline

#15 2009-05-03 12:24:27

Nicky
#! CrunchBanger
From: Paris (France)
Registered: 2009-04-05
Posts: 163

Re: Openbox weather pipe menu

In fact I put it directly in the script:
f = urllib.urlopen("http://www.google.fr/ig/api?weather=paris")

and even if I put it in menu.xml it doesn't work hmm

Offline

#16 2009-05-03 12:58:19

rfquerin
Inkscape Ninja
From: Beeton, Ontario, Canada
Registered: 2009-01-05
Posts: 383
Website

Re: Openbox weather pipe menu

I compared what your script generated and what mine generated. The only difference I see that could make a difference is the apostrophe in "l'ensemble".  Right now the script generates the xml strings using single quotes, so the strings are probably getting screwed up.

If you modify the python script to generate the xml strings using double quotes instead of single quotes it would eliminate the problem I think. Can xml run with double quotes? That's the only thing I'm not sure of.

Offline

#17 2009-05-03 13:04:50

Nicky
#! CrunchBanger
From: Paris (France)
Registered: 2009-04-05
Posts: 163

Re: Openbox weather pipe menu

Yes it is what I said, there is maybe a problem with ' in "l'ensemble", but it shouldn't make the script totally not working.

When I put it directly in the menu.xml, in fact it make a line where it is printed: Temps: nuageux dans l

But maybe there is something like for the "à" to translate it in something else.

Offline

#18 2009-05-03 13:54:49

rfquerin
Inkscape Ninja
From: Beeton, Ontario, Canada
Registered: 2009-01-05
Posts: 383
Website

Re: Openbox weather pipe menu

Nicky wrote:

Yes it is what I said, there is maybe a problem with ' in "l'ensemble", but it shouldn't make the script totally not working.

When I put it directly in the menu.xml, in fact it make a line where it is printed: Temps: nuageux dans l

But maybe there is something like for the "à" to translate it in something else.

Good news.. I took your original script and then changed it so that it generated double quotes inside the xml entries instead of single quotes. I called it from my menu and it seems to work! smile

I've attached the modified script right here (I also changed the misspellings of maximum and minimum in the script too just because it bugged me wink ):

#!/usr/bin/python

import sys
import urllib
from string import maketrans
#from xml.sax import make_parser, handler
from xml.sax import handler, parseString
class ElementProcesser(handler.ContentHandler):
    
    def startElement(self, name, attrs):
        
        if name == "city":
            print "<separator label=\"" + attrs["data"] + "\" />"
        elif name == "current_conditions":
            print "<separator label=\"Conditions actuelles\" />"
        elif name == "condition":
            print "<item label=\"Temps: " + attrs["data"] + "\" />"
        elif name == "humidity":
            print "<item label=\"" + attrs["data"] + "\" />"
        elif name == "wind_condition":
            print "<item label=\"" + attrs["data"] + "\" />"
        elif name == "day_of_week":
            print "<separator label=\"" + self.getDayOfWeek(attrs["data"]) + "\" />"
            
        #Celsius
        elif name == "temp_c":
            print "<item label=\"Temperature " + attrs["data"] + " C\" />"
        elif name == "low":
            print "<item label=\"Minimum " + attrs["data"] + " C\" />"
        elif name == "high":
            print "<item label=\"Maximum " + attrs["data"] + " C\" />"
        
        #Fahrenheit
        #elif name == "temp_f":
            #print "<item label=\"Temperature " + attrs["data"] + " F\" />"
        #elif name == "low":
            #print "<item label=\"Minimum " + attrs["data"] + " F\" />"
        #elif name == "high":
            #print "<item label=\"Maximum " + attrs["data"] + " F\" />"
        
        
    def endElement(self, name):
        
        if name == "current_conditions":
            print "<separator label=\"Previsions\" />"
        
    
    def startDocument(self):
        print "<openbox_pipe_menu>"
    
    def endDocument(self):
        print "</openbox_pipe_menu>"
    
    def getDayOfWeek(self,day):
        
        #Francais
        if day == "lun.":
            return "Lundi"
        elif day == "mar.":
            return "Mardi"
        elif day == "mer.":
            return "Mercredi"
        elif day == "jeu.":
            return "Jeudi"
        elif day == "ven.":
            return "Vendredi"
        elif day == "sam.":
            return "Samedi"
        elif day == "dim.":
            return "Dimanche"
        
        else:
            return day

# You should use your local version of google to have the messages in your language and metric system
f = urllib.urlopen("http://www.google.fr/ig/api?weather=paris")
xml = f.read()
f.close()

#Avoid problems with non english characters
trans=maketrans("\xe1\xe9\xed\xf3\xfa\xe0","aeioua")
xml = xml.translate(trans)

#parser.parse("http://www.google.es/ig/api?weather="+sys.argv[1])
parseString(xml,ElementProcesser())

Give this a shot and see if it works now.

Offline

#19 2009-05-03 19:05:57

Nicky
#! CrunchBanger
From: Paris (France)
Registered: 2009-04-05
Posts: 163

Re: Openbox weather pipe menu

Perfect !
I love you tongue

Offline

#20 2009-05-06 16:53:30

tchoklat
Member
Registered: 2009-05-01
Posts: 18

Re: Openbox weather pipe menu

Newbie here! This is great as I have been looking for a way to have the weather on my desktop and cannot work out how to add it to my basic conky script. What do I do with this script? Where do I put it? How do I make it work?


regards


tchoklat


"I just don't give a damn!"

Offline

#21 2009-05-06 17:49:26

Nicky
#! CrunchBanger
From: Paris (France)
Registered: 2009-04-05
Posts: 163

Re: Openbox weather pipe menu

You put the script where you want, the best is in a file scripts in your home where you will put all the scripts you have.

And in the menu.xml (win+space >  Preferences > Openbox config > edit menu.xml) you add a line which look like this one:

<menu execute="python ~/path_to_script/name_of_script YOURCITY" id="weather" label="Weather"/>

You can also click on the link given in the first message here everything is explained wink

Offline

#22 2009-05-16 09:28:43

Nicky
#! CrunchBanger
From: Paris (France)
Registered: 2009-04-05
Posts: 163

Re: Openbox weather pipe menu

It doesn't work any more :'(
I understand nothing any more, it works with google.com or google.es or whatever but not with google.fr
And it isn't logical, You could think when you see the result of the script in terminal that it is the humidity which doesn't work, but even if I remove it doesn't change anything. Even if I let only the conditions and the temperatures which seems working the script give the same result :

<openbox_pipe_menu>
<separator label="Paris, IDF" />
<separator label="Conditions actuelles" />
<item label="Temps: Nuageux dans l'ensemble" />
<item label="Temperature 13 C" />
Traceback (most recent call last):
  File "meteo", line 85, in <module>
    parseString(xml,ElementProcesser())
  File "/usr/lib/python2.5/xml/sax/__init__.py", line 49, in parseString
    parser.parse(inpsrc)
  File "/usr/lib/python2.5/xml/sax/expatreader.py", line 107, in parse
    xmlreader.IncrementalParser.parse(self, source)
  File "/usr/lib/python2.5/xml/sax/xmlreader.py", line 123, in parse
    self.feed(buffer)
  File "/usr/lib/python2.5/xml/sax/expatreader.py", line 211, in feed
    self._err_handler.fatalError(exc)
  File "/usr/lib/python2.5/xml/sax/handler.py", line 38, in fatalError
    raise exception
xml.sax._exceptions.SAXParseException: <unknown>:1:523: not well-formed (invalid token)

I don't know what is in the problem in google.fr but I will finish to use the Spanish one and make a translation neutral

Offline

#23 2009-12-17 03:59:41

tawan
#! Junkie
Registered: 2009-01-30
Posts: 385
Website

Re: Openbox weather pipe menu

** This is completely simple to set up now **

tMzBoOA

take the location code from a conky weather you probably have e.g. ASXX0112 (Sydney, Australia)

and add it to this

  <menu id="pipe-weather" label="Weather" execute="python ~/.config/openbox/scripts/yweather.py AYXX0001 Celsius" />

(you can of course change Celsius to Fahrenheit

Put that in you menu.xml

Then save this in the location pointed to by the above menu call (~/.config/openbox/scripts/yweather.py)

#!/usr/bin/python

import urllib
from xml.etree.cElementTree import parse
from datetime import datetime, timedelta
import os
from os.path import join
from sys import argv
try:
    import cPickle as pickle
except ImportError:
    import pickle

#Usage: yweather.py AYXX0001 Celsius

if len(argv) != 3:
    raise Exception('Usage: yweather.py zip_code units. zip_code is your city code in Yahoo Weather, units can be Celsius or Fahrenheit.')
else:
    zip_code = argv[1]
    if argv[2] == 'Fahrenheit' or argv[2] == 'fahrenheit':
        units = 'f'
    else:
        units = 'c'



CACHE_HOURS = 6

#http://weather.yahooapis.com/forecastrss
WEATHER_URL = 'http://xml.weather.yahoo.com/forecastrss?p=%s&u=%s'
WEATHER_NS = 'http://xml.weather.yahoo.com/ns/rss/1.0'

def weather_for_zip(zip_code, units):
    url = WEATHER_URL % (zip_code, units)
    rss = parse(urllib.urlopen(url)).getroot()
    forecasts = []
    for element in rss.findall('channel/item/{%s}forecast' % WEATHER_NS):
        forecasts.append(dict(element.items()))
    ycondition = rss.find('channel/item/{%s}condition' % WEATHER_NS)
    return {
        'current_condition': dict(ycondition.items()),
        'forecasts': forecasts,
        'title': rss.findtext('channel/title'),
        'pubDate': rss.findtext('channel/item/pubDate'), #rss.findtext('channel/lastBuildDate'),
        'location': dict(rss.find('channel/{%s}location' % WEATHER_NS).items()),
        'wind': dict(rss.find('channel/{%s}wind' % WEATHER_NS).items()),
        'atmosphere': dict(rss.find('channel/{%s}atmosphere' % WEATHER_NS).items()),
        'astronomy': dict(rss.find('channel/{%s}astronomy' % WEATHER_NS).items()),
        'units': dict(rss.find('channel/{%s}units' % WEATHER_NS).items())
    }

def print_openbox_pipe_menu(weather):
    print '<openbox_pipe_menu>'
    print '<separator label="%s %s" />' % (weather['location']['city'],weather['pubDate'])
    print '<separator label="Current conditions" />'
    print '<item label="Weather: %s" />' % weather['current_condition']['text']
    print '<item label="Temperature: %s %s" />' % ( weather['current_condition']['temp'],
                                          weather['units']['temperature'] )
    print '<item label="Humidity: %s%%" />' % weather['atmosphere']['humidity']
    print '<item label="Visibility: %s %s" />' % ( weather['atmosphere']['visibility'],
                                          weather['units']['distance'] )
    
    #pressure: steady (0), rising (1), or falling (2)
    if weather['atmosphere']['rising'] == 0:
        pressure_state = 'steady'
    elif weather['atmosphere']['rising'] == 1:
        pressure_state = 'rising'
    else:
        pressure_state = 'falling'
    print '<item label="Pressure: %s %s (%s)" />' % ( weather['atmosphere']['pressure'],
                                          weather['units']['pressure'], pressure_state )
    print '<item label="Wind chill: %s %s" />' % ( weather['wind']['chill'],
                                          weather['units']['temperature'] )
    print '<item label="Wind direction: %s degrees" />' % weather['wind']['direction']
    print '<item label="Wind speed: %s %s" />' % ( weather['wind']['speed'],
                                          weather['units']['speed'] )
    print '<item label="Sunrise: %s" />' % weather['astronomy']['sunrise']
    print '<item label="Sunset: %s" />' % weather['astronomy']['sunset']
    for forecast in weather['forecasts']:
        print '<separator label="Forecast: %s" />' % forecast['day']
        print '<item label="Weather: %s" />' % forecast['text']
        print '<item label="Min temperature: %s %s" />' % ( forecast['low'],
                                                weather['units']['temperature'] )
        print '<item label="Max temperature: %s %s" />' % ( forecast['high'],
                                                weather['units']['temperature'] )
    print '</openbox_pipe_menu>'

cache_file = join(os.getenv("HOME"), '.yweather.cache')

try:
    f = open(cache_file,'rb')
    cache = pickle.load(f)
    f.close()
except IOError:
    cache = None

if cache == None or (zip_code, units) not in cache or (
        cache[(zip_code, units)]['date'] + timedelta(hours=CACHE_HOURS) < datetime.utcnow()):
    # The cache is outdated
    weather = weather_for_zip(zip_code, units)
    if cache == None:
        cache = dict()
    cache[(zip_code, units)] = {'date': datetime.utcnow(), 'weather': weather}
    
    #Save the data in the cache
    try:
        f = open(cache_file, 'wb')
        cache = pickle.dump(cache, f, -1)
        f.close()
    except IOError:
        raise
else:
    weather = cache[(zip_code, units)]['weather']


print_openbox_pipe_menu(weather)

Thanks to NoalWin at ArchLinux forums, it is so easy.

Last edited by tawan (2009-12-17 04:05:48)


I blog too much....       geek stuff LinuxMintDebian | linux noob stuff LinuxMintNoob | spiritual stuff Daily Cup of Tao

Offline

#24 2009-12-17 07:54:08

steen
#! CrunchBanger
From: Denmark
Registered: 2009-08-31
Posts: 149
Website

Re: Openbox weather pipe menu

Thanx tawan

I like this, but it seems that yahooweather can only tell you the winddirection in degrees. How would I go about getting it to show in direction like ENE, S etc. instead???


"You bow to NOone..."

Offline

Be excellent to each other!

#25 2009-12-17 13:14:36

tawan
#! Junkie
Registered: 2009-01-30
Posts: 385
Website

Re: Openbox weather pipe menu

steen wrote:

Thanx tawan

I like this, but it seems that yahooweather can only tell you the winddirection in degrees. How would I go about getting it to show in direction like ENE, S etc. instead???

I guess add to the phython script so that Xdegrees = North and so on... hmm

Or maybe look at the Yahoo API and see if they output that info..

Sorry I can't really help on either of them, I am simply a code theif wink


I blog too much....       geek stuff LinuxMintDebian | linux noob stuff LinuxMintNoob | spiritual stuff Daily Cup of Tao

Offline

Board footer

Powered by FluxBB

Copyright © 2012 CrunchBang Linux.
Proudly powered by Debian. Hosted by Linode.
Debian is a registered trademark of Software in the Public Interest, Inc.

Debian Logo