You are not logged in.

#1 2011-10-16 19:10:25

pyther
Member
Registered: 2008-01-21
Posts: 1,395
Website

Conky - Weather Underground Script

Since weather.com is ending their free XOAP service conkyForecast will no longer work at the end of this month.

Therefore I wrote a small script to get the temperature and condition from Weather Underground

#!/usr/bin/python
#
# Fetches Weather info from Weather Underground
#
# Usage: ./wundergound.py zipcode
#
# International:
#  * Go to http://www.wunderground.com/
#  * Find your city
#  * Click the RSS icon
#  * Station ID is the number that follows /stations/ in the url
#
#

# Values are either True or False
metric=False
international=False

import sys
import feedparser

def usage():
    print("Usage:")
    if international:
        print("  ./wunderground.py StationID")
    else:
        print("  ./weunderground.py zipcode")
    sys.exit(1)

if not len(sys.argv) == 2:
    usage()

location=sys.argv[1]

if international:
    url="http://rss.wunderground.com/auto/rss_full/global/stations/"
else:
    url="http://rss.wunderground.com/auto/rss_full/"

feed=feedparser.parse(url+location)

if not feed.feed:
    # Assume Error
    print("Error")
    sys.exit(1)

current=feed['items'][0].title

if metric:
    temp=current.split(",")[0].split(":")[1].split("/")[1].strip()
else:
    temp=current.split(",")[0].split(":")[1].split("/")[0].strip()

condition=current.split(",")[1].split("-")[0].strip()

print(temp, "-", condition)

Example:

$ ./wunderground 11201
69.6F - Clear

Conky:

${execi 600 /home/pyther/scripts/wunderground 11201}

Enjoy!


Website - Blog - arch-home
Arch User since March 2005

Offline

#2 2011-10-20 06:26:38

Snakeye
Member
From: Surrey BC
Registered: 2009-12-19
Posts: 91

Re: Conky - Weather Underground Script

Crap didn't know, glad i spotted this while browsing! Good work! smile

Offline

#3 2011-10-28 10:55:51

Narga
Member
From: Hải Phòng, Việt Nam
Registered: 2011-10-06
Posts: 60
Website

Re: Conky - Weather Underground Script

Thanks, but Weather Underground not support my location

Offline

#4 2011-10-29 12:22:18

7etc/
Member
Registered: 2010-05-08
Posts: 47

Re: Conky - Weather Underground Script

So, you, re saying the yaourt packages for conky (conkyforecast and -bzr) are going to become useless? I like this packages!!!.

Offline

#5 2011-12-08 18:55:15

ianux
Member
From: France
Registered: 2008-12-02
Posts: 16

Re: Conky - Weather Underground Script

conkyforecast-bzr since r66 supports WU (but lacks locale and weather fonts support) which should become the default. You still need a (free) API key.

Offline

#6 2011-12-14 05:22:34

Lacoste
Member
Registered: 2011-12-14
Posts: 1

Re: Conky - Weather Underground Script

Syntax seems to have changed.  For those who don't know Python, there are some newer scripts mentioned here:  http://kubuntuforums.net/forums/index.p … =3118776.0

Offline

#7 2011-12-14 12:41:51

pyther
Member
Registered: 2008-01-21
Posts: 1,395
Website

Re: Conky - Weather Underground Script

What do you mean by the syntax has changed?


Website - Blog - arch-home
Arch User since March 2005

Offline

#8 2011-12-14 17:35:50

swanson
Member
From: Sweden
Registered: 2011-02-05
Posts: 759

Re: Conky - Weather Underground Script

The script works fine but I'd like to modify it a bit. Can anyone point me to a good tutorial on feedparser?  I've googled but only found raw guides for programmers.

Offline

#9 2011-12-14 17:51:09

pyther
Member
Registered: 2008-01-21
Posts: 1,395
Website

Re: Conky - Weather Underground Script

Here is the documentation for feedparser: http://packages.python.org/feedparser/

What exactly are you trying to do? In the script feedparser is getting the first rss entry and parsing it.

If you want the afternoon, night, or next day entries...
afternoon=feed['items'][1].title # afternoon
tonight=feed['items'][2].title # Tonight
tomorrow=feed['items'][3].title # tomorrow


Website - Blog - arch-home
Arch User since March 2005

Offline

#10 2011-12-14 18:19:26

swanson
Member
From: Sweden
Registered: 2011-02-05
Posts: 759

Re: Conky - Weather Underground Script

Thanks just what I was looking for!

Offline

#11 2011-12-15 07:55:48

Paul-S
Member
From: Wales
Registered: 2008-02-04
Posts: 353

Re: Conky - Weather Underground Script

Thanks for the script pyther, did anyone modify it for like a 2 or 3 day forecast? Any chance of posting it, thanks.

Cheers
Paul-S

Offline

#12 2011-12-15 19:00:21

swanson
Member
From: Sweden
Registered: 2011-02-05
Posts: 759

Re: Conky - Weather Underground Script

Working on it ...

Offline

Board footer

Powered by FluxBB