You are not logged in.

#1 2007-09-14 20:26:09

buttons
Member
From: NJ, USA
Registered: 2007-08-04
Posts: 620

Conky - Really Simple Weather Script

Well, I tried weatherget and it consumes a lot of resources each time it checks.  This just isn't good at all on systems that might depend on that CPU time for something else, like games.  Plus it's distracting to see that silly CPU spike on the graph.

Requires curl and perl.

#!/bin/sh
#AccuWeather (r) RSS weather tool for conky
#
#USAGE: weather.sh <locationcode>
#
#(c) Michael Seiler 2007

METRIC=1 #Should be 0 or 1; 0 for F, 1 for C

if [ -z $1 ]; then
    echo
    echo "USAGE: weather.sh <locationcode>"
    echo
    exit 0;
fi

curl -s http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=$1 | perl -ne 'if (/Currently/) {chomp;/\<title\>Currently: (.*)?\<\/title\>/; print "$1"; }'

Change METRIC to suit your taste.

In your conkyrc, the line should be something like so:

${execi 300 /home/buttons/bin/weather.sh 08534}

Which produces (at the moment) "Mostly Sunny: 24C"

Note you can use anything for the (accuweather) location code and it should work.  If you're not in the US, put your location code in quotes, like so:

${execi 300 /home/buttons/bin/weather.sh "EUR|UK|UK118|Amersham"}

Which produces "Mostly Clear: 15C"

Location codes can be found on accuweather's website, accuweather.com.  Within the US, this is just the ZIP code.


Cthulhu For President!

Offline

#2 2007-09-16 08:14:20

somedrew
Member
From: Canada
Registered: 2007-05-14
Posts: 140

Re: Conky - Really Simple Weather Script

Thanks!

Offline

#3 2008-01-24 21:50:04

bionnaki
Member
Registered: 2006-09-05
Posts: 289

Re: Conky - Really Simple Weather Script

works great. thanks!

Offline

#4 2008-01-25 12:16:44

Raisuli
Member
Registered: 2007-09-28
Posts: 135

Re: Conky - Really Simple Weather Script

Exactly what I was looking for. Thanks!

Offline

#5 2008-01-25 13:55:12

xd-0
Member
From: Sweden
Registered: 2007-11-02
Posts: 327
Website

Re: Conky - Really Simple Weather Script

Is it okey if I use your script in a howto on a swedish wiki?

Offline

#6 2008-01-25 15:32:26

buttons
Member
From: NJ, USA
Registered: 2007-08-04
Posts: 620

Re: Conky - Really Simple Weather Script

xd-0 wrote:

Is it okey if I use your script in a howto on a swedish wiki?

Yepper.


Cthulhu For President!

Offline

#7 2008-01-28 14:58:30

goethe
Member
Registered: 2008-01-09
Posts: 25

Re: Conky - Really Simple Weather Script

Thanks for the nice script! But I can't find the location codes on the website you mentioned. I'm living in Berlin, Germany. Do you have a link?

Offline

#8 2008-01-28 17:29:26

buttons
Member
From: NJ, USA
Registered: 2007-08-04
Posts: 620

Re: Conky - Really Simple Weather Script

EUR|DE|GM003|BERLIN

The easiest way is to go to accuweather.com and search up your location.  Once you've done that, take a look at the URL, which in this case is

The bit in bold is the part to look for, which shows locCode (the location code) is EUR|DE|GM003|BERLIN

and

weather.sh "EUR|DE|GM003|BERLIN"

gives Rain/drizzle: 7C at the time of this writing, which is warm by northeast US winter standards wink


Cthulhu For President!

Offline

#9 2008-03-08 20:41:59

serrghi
Member
From: Bergen, NO
Registered: 2008-02-12
Posts: 100
Website

Re: Conky - Really Simple Weather Script

thanks alot! works perfect!


Unyttig.INFO - Your source to not so useless information
My github - Various configs, dotfiles and nifty scripts

Offline

#10 2008-07-27 02:40:17

Lyceuhns
Member
From: João Pessoa, Paraíba, Brasil
Registered: 2008-05-09
Posts: 121

Re: Conky - Really Simple Weather Script

Great! Useful.
Thanks!

Offline

#11 2008-07-27 18:28:46

Lyceuhns
Member
From: João Pessoa, Paraíba, Brasil
Registered: 2008-05-09
Posts: 121

Re: Conky - Really Simple Weather Script

Just a question:
Wouldn't it better and easy with the Weather Channel info?

Last edited by Lyceuhns (2008-07-27 18:29:25)

Offline

#12 2008-07-28 01:20:48

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,217
Website

Re: Conky - Really Simple Weather Script

A quick tweak to include a default location, which can be over-ridden by the command line smile

Change the LOCCOD variable to your default location, then you can call it just by running the script. Or leave it blank and it will be ignored (printing the usage message if a command line argument isn't given.

#!/bin/sh
#AccuWeather (r) RSS weather tool for conky
#
#USAGE: weather.sh <locationcode>
#
#(c) Michael Seiler 2007

METRIC=1 #Should be 0 or 1; 0 for F, 1 for C
LOCCOD=""  # Example: OCN|AU|VIC|MELBOURNE

if [ -z $1 ] && [ -x $LOCCOD ] ; then
        echo
        echo "USAGE: $0 [locationcode]"
        echo
        exit 0;
elif [ ! -z $1 ] ; then
        LOCCOD=$1
fi

curl -s http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=$LOCCOD | perl -ne 'if (/Currently/) {chomp;/\<title\>Currently: (.*)?\<\/title\>/; print "$1"; }'

Last edited by fukawi2 (2008-07-28 01:22:48)

Offline

#13 2009-01-25 09:14:09

Alexdsan
Member
Registered: 2007-07-10
Posts: 28

Re: Conky - Really Simple Weather Script

Hi.

How to convert the state of the time for another language?

example:
Cloudy = Nublado
Sunny = Ensolarado
T-Storms = Pancada
....

Offline

#14 2009-01-26 14:14:33

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

Re: Conky - Really Simple Weather Script

Can I suggest using --connect-timeout 30 ?

Every now and then the curl connection will hang, which results in conky not updating. If I kill the curl process, conky updates right away.


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

Offline

#15 2009-01-28 14:58:54

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

Re: Conky - Really Simple Weather Script

Alexdsan wrote:

Hi.

How to convert the state of the time for another language?

example:
Cloudy = Nublado
Sunny = Ensolarado
T-Storms = Pancada
....

Here you go... it should be straight forward on how to add a new item, just follow the syntax...
Feel free to ask any questions...

#!/bin/sh
#AccuWeather (r) RSS weather tool for conky
#
#USAGE: weather.sh <locationcode>
#
#(c) Michael Seiler 2007

METRIC=0 #Should be 0 or 1; 0 for F, 1 for C

if [ -z $1 ]; then
    echo
    echo "USAGE: weather.sh <locationcode>"
    echo
    exit 0;
fi

#curl -s http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=$1 | perl -ne 'if (/Currently/) {chomp;/\<title\>Currently: (.*)?\<\/title\>/; print "$1"; }'

out=`curl --connect-timeout 30 -s http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=$1 | perl -ne 'if (/Currently/) {chomp;/\<title\>Currently: (.*)?\<\/title\>/; print "$1"; }'`

#echo $out

cond=`echo $out | cut -d':' -f 1`
temp=`echo $out | cut -d':' -f 2`

case "$cond" in

'Fog')
    echo -e "Nombre\c"
;;
'Snow')
    echo -e "Nevado\c"
;;
'Cloudy')
    echo -e "Nublado\c"
;;
'Sunny')
   echo -e "Ensolarado\c"
;;
'T-Storms')
   echo -e "Pancada\c"
;;
*)
   echo -e  $cond'\c'
esac

echo : $temp

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

Offline

#16 2009-01-28 15:15:35

userlander
Member
Registered: 2008-08-23
Posts: 413

Re: Conky - Really Simple Weather Script

cool - works great!

The accuweather URL didn't list that info for me, so I just used my zip code. "weather.sh" seemed kind of generic, so I named mine "weatherconk" big_smile

Offline

#17 2009-01-28 16:21:16

Alexdsan
Member
Registered: 2007-07-10
Posts: 28

Re: Conky - Really Simple Weather Script

pyther wrote:

Here you go... it should be straight forward on how to add a new item, just follow the syntax...
Feel free to ask any questions...

Thanks for help smile

Offline

#18 2009-01-28 16:33:19

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

Re: Conky - Really Simple Weather Script

Sure no problem...

Does anyone have a problem with the curl command hanging every now and then?


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

Offline

#19 2009-02-03 14:14:18

userlander
Member
Registered: 2008-08-23
Posts: 413

Re: Conky - Really Simple Weather Script

pyther wrote:

Sure no problem...

Does anyone have a problem with the curl command hanging every now and then?

Same here. The script seems to lock up conky at least once a day. Not sure if it's something to do with curl or the connection to accuweather maybe? Whatever it is, I had to stop using it. sad

Offline

#20 2009-03-06 20:44:32

eDio
Member
From: Ukraine, Kyiv
Registered: 2008-12-02
Posts: 422

Re: Conky - Really Simple Weather Script

Conky reports
sh: /home/edio/.common/conky_weather.sh: Permission denied

How can I fix this?

Offline

#21 2009-03-06 21:05:26

brisbin33
Member
From: boston, ma
Registered: 2008-07-24
Posts: 1,796
Website

Re: Conky - Really Simple Weather Script

pyther wrote:

Sure no problem...

Does anyone have a problem with the curl command hanging every now and then?

adding "--connect-timeout 30" to the curl options fixed this for me.  your mileage may vary.

edit: oops.... just read back, that's already been mentioned.... by you, probably where i found it in the first place, circular linux hints ftw!

Last edited by brisbin33 (2009-03-06 21:08:45)

Offline

#22 2009-03-06 21:11:45

haxit
Member
From: /home/haxit
Registered: 2008-03-04
Posts: 1,247
Website

Re: Conky - Really Simple Weather Script

Great script!


Archi686 User | Old Screenshots | Old .Configs
Vi veri universum vivus vici.

Offline

#23 2009-03-07 09:05:33

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,217
Website

Re: Conky - Really Simple Weather Script

eDio wrote:

Conky reports
sh: /home/edio/.common/conky_weather.sh: Permission denied

How can I fix this?

You need to make it executable:

chmod +x /home/edio/.common/conky_weather.sh

Offline

#24 2009-03-07 19:20:42

eDio
Member
From: Ukraine, Kyiv
Registered: 2008-12-02
Posts: 422

Re: Conky - Really Simple Weather Script

fukawi2
Thank you... I tried all things about permissions, and setting them to rwxrwxrwx (oct: 0777) solves my problem.
But now I know, that I have to make scripts executable...
P.S. Looks like Linux is smarter, than I am %)

Offline

#25 2009-03-07 20:53:51

renuvio
Member
Registered: 2008-10-25
Posts: 49

Re: Conky - Really Simple Weather Script

This script runs without problem here.
I use it in conky as explained in this post, and is very useful too in the CLI.
For example, if anyone is looking for, this is the location code for Mexico City, and running this

./clima.sh "NAM|MX|MX009|MEXICO_CITY"

in the CLI does the task.

Thanks Buttons!

Offline

Board footer

Powered by FluxBB