You are not logged in.

#26 2009-04-06 00:34:50

NME
Member
Registered: 2004-10-13
Posts: 25

Re: Conky - Really Simple Weather Script

just came looking for this. still works. thanks a lot, use it for a motd.

Offline

#27 2009-04-06 06:56:18

SanskritFritz
Member
From: Budapest, Hungary
Registered: 2009-01-08
Posts: 1,600
Website

Re: Conky - Really Simple Weather Script

Check out this one:
http://ubuntuforums.org/showthread.php?t=869328

Last edited by SanskritFritz (2009-04-06 07:06:31)


zʇıɹɟʇıɹʞsuɐs AUR || Cycling in Budapest with a helmet camera || Revised log levels proposal: "FYI" "WTF" and "OMG" (John Barnette)

Online

#28 2009-04-06 15:07:26

elmer_42
Member
From: /na/usa/ca
Registered: 2008-10-11
Posts: 427

Re: Conky - Really Simple Weather Script

Oh, cool. This is a neat script, thanks!


[ lamy + pilot ] [ arch64 | wmii ] [ ati + amd ]

Offline

#29 2009-06-11 23:08:22

fflarex
Member
Registered: 2007-09-15
Posts: 466

Re: Conky - Really Simple Weather Script

Here's a variation on this script that I made. I think it formats the output a little nicer.

#!/bin/sh

METRIC=1  # 0 for F, 1 for C

curl -s http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=$1 \
| sed -n '/Currently:/ s/.*: \(.*\): \([0-9]*\)\([CF]\).*/\2°\3, \L\1/p'

It returns something like "17°C, mostly sunny". You can remove the "\L" if you don't like lowercase letters as much as I do.

Last edited by fflarex (2009-06-15 15:22:34)

Offline

#30 2009-06-15 14:10:02

Pank
Member
From: IT
Registered: 2009-06-13
Posts: 370

Re: Conky - Really Simple Weather Script

Could one somehow use the weather font with this script? I.e. update the icon based on the condition?


Arch x64 on Thinkpad X200s/W530

Offline

#31 2009-06-15 15:19:42

fflarex
Member
Registered: 2007-09-15
Posts: 466

Re: Conky - Really Simple Weather Script

Yeah, it wouldn't really be that hard, but it would be very tedious to set up initially. It would also turn this one-liner into a much longer script. Not worth it, in my opinion, as there are existing weather scripts that make use of that font that I've seen around the forums.

Offline

#32 2009-06-17 00:49:18

marb
Member
Registered: 2007-12-11
Posts: 6

Re: Conky - Really Simple Weather Script

fflarex wrote:

Yeah, it wouldn't really be that hard, but it would be very tedious to set up initially. It would also turn this one-liner into a much longer script. Not worth it, in my opinion, as there are existing weather scripts that make use of that font that I've seen around the forums.

Like pogodynka (it's in AUR).

Offline

#33 2009-06-20 21:40:46

ak00
Member
Registered: 2009-06-20
Posts: 4

Re: Conky - Really Simple Weather Script

thanks for the script! after a little work, it's working great for me.

i was wondering how i could change the script to output: "condition ##F" i.e. "Partly Sunny 96F" WITHOUT the colon after the condition as is the normal output (Partly Cloudy: 96F). i tried to learn a bit of perl and look at the script a bit but can't seem to figure it out.. any perl-comfortable people know how?

@fflarex: i used your script, but it outputs on my desktop as "17A°C, mostly sunny" but i can't get the "A" to go away...

Last edited by ak00 (2009-06-20 21:46:54)

Offline

#34 2009-06-20 22:22:40

fflarex
Member
Registered: 2007-09-15
Posts: 466

Re: Conky - Really Simple Weather Script

@ak00: Can you replace line 6 in my script with "| grep Currently:" (instead of the huge sed command) and post the output you get? It might help me figure out what went wrong in your case.

Last edited by fflarex (2009-06-20 22:22:59)

Offline

#35 2009-06-21 01:32:54

ak00
Member
Registered: 2009-06-20
Posts: 4

Re: Conky - Really Simple Weather Script

fflarex wrote:

@ak00: Can you replace line 6 in my script with "| grep Currently:" (instead of the huge sed command) and post the output you get? It might help me figure out what went wrong in your case.

it outputs: "<title>Currently: Partly Sunny: 35" (without the quotes) . . .

the current code i use is:

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

and it outputs: "Partly Sunny: 95F"

what i want is 95° partly sunny or partly sunny 95° .. like your script just without the colon or C/F marker.. thanks for your help.

Offline

#36 2009-06-21 01:44:26

fflarex
Member
Registered: 2007-09-15
Posts: 466

Re: Conky - Really Simple Weather Script

@ak00: Well I really have no idea what was causing that A to show up when you used my script. Maybe you copied my script wrong? I don't mean to place the blame on you but I really can't figure it out.

Anyways, here's a variation of my script to get the format you want. Let me know if it works for you:

#!/bin/sh

METRIC=1  # 0 for F, 1 for C

curl -s http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=$1 \
| sed -n '/Currently:/ s/.*: \(.*\): \([-0-9]*\)\([CF]\).*/\2° \L\1/p' | sed 's/A°/°/'

If you want the conditions in front of the temperature change "/\2° \L\1/" to "/\L\1 \2°/".

Last edited by fflarex (2009-12-12 20:03:36)

Offline

#37 2009-06-21 02:03:08

ak00
Member
Registered: 2009-06-20
Posts: 4

Re: Conky - Really Simple Weather Script

yea still not much luck ... i'll just play around a bit more.. it COULD be because i am trying it on crunchbang.. and i have had an experience in the past where conky works a little different on one distro than another though i don't know why it would... thanks for your help though man! i appreciate it!! smile

right now my desktop is:

desktopbqd.jpg

so you kind of see the essential info thing i'm trying to go for..

Offline

#38 2009-06-21 02:54:36

fflarex
Member
Registered: 2007-09-15
Posts: 466

Re: Conky - Really Simple Weather Script

I've edited the script above. This is an ugly hack, but might get rid of the extra A you seem to be having troubles with.

Offline

#39 2009-06-21 16:43:27

ak00
Member
Registered: 2009-06-20
Posts: 4

Re: Conky - Really Simple Weather Script

hmmm im using your original script right now but just without the ° symbol.. i think the problem is the way my computer wants to render the ° sign. it produces "95F mostly cloudy" ... thanks! smile

Offline

#40 2009-08-17 12:46:09

The_Eddster
Member
Registered: 2009-08-17
Posts: 1

Re: Conky - Really Simple Weather Script

The weather thingy isn't working. I'm getting this error when I load up conky:
/home/eddy/bin/weather.sh: 17: curl: not found

This is the code I use in my config file:
WEATHER ${hr 2}
${voffset 8}${font Arial Black:size=14}${alignc}${execi 300 /home/eddy/bin/weather.sh "EUR|UK|UK126|Coventry"}

And this is the weather.sh (the same as the weather.sh script at the start of this post):
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/liveweat … ocCode\=$1 | perl -ne 'if (/Currently/) {chomp;/\<title\>Currently: (.*)?\<\/title\>/; print "$1"; }'


Is there something I'm doing wrong?

Offline

#41 2009-12-12 08:40:11

Berseker
Member
From: Near Lecco, Italy
Registered: 2008-04-24
Posts: 252

Re: Conky - Really Simple Weather Script

The_Eddster wrote:

The weather thingy isn't working. I'm getting this error when I load up conky:
/home/eddy/bin/weather.sh: 17: curl: not found
..
Is there something I'm doing wrong?

you missed to install curl from extra
anyway, I'm trying this but now it doesn't work. It simply runs but it returns nothing. Does anyone have this problem too?

Last edited by Berseker (2009-12-12 08:41:26)

Offline

#42 2009-12-12 20:03:22

fflarex
Member
Registered: 2007-09-15
Posts: 466

Re: Conky - Really Simple Weather Script

I started having troubles with my variant of it a couple weeks ago. I realized I hadn't taken sub-zero temperatures into account. Easy fix, just change [0-9] in the sed expression to [-0-9]. I edited my earlier post with the fix.

Offline

#43 2009-12-12 20:53:26

mjheagle8
Member
From: /home/mjheagle8
Registered: 2009-07-12
Posts: 186

Re: Conky - Really Simple Weather Script

i'm happily using this script and it works great, thanks!


Desktop/Laptop - DWM :: VM - screen
Registered Linux User Number 483137 :: Victory! :: GitHub

Offline

#44 2009-12-12 23:15:41

Kitty
Member
From: The Burning Desert
Registered: 2008-01-11
Posts: 88

Re: Conky - Really Simple Weather Script

Here's a one liner for dumping the yahoo forecast into a file to be read by conky:

curl --silent "http://xml.weather.yahoo.com/forecastrss?p=USAZ0052&u=f"| sed -e '/F<BR\|Low/!d; s/<.*>//'

Change the USAZ0052 to the code for your locale. If you want celsius, change the '=f' to '=c' and 'F<BR' to 'C<BR'.

My matching cron job to save it to a file:

30 *  *   *   *  <home>/bin/myweather.sh > /dev/shm/weather-update.txt

Sample output:

$ cat /dev/shm/weather-update.txt 
Mostly Cloudy, 45 F
Sat - Showers Late. High: 49 Low: 41
Sun - Showers. High: 48 Low: 34

Edit: removed a superfluous grep

Last edited by Kitty (2009-12-13 00:40:11)


/etc/rc.d/ is where daemons reside. Beware.

Offline

#45 2010-05-11 03:41:12

kaikaizi
Member
Registered: 2010-05-11
Posts: 10

Re: Conky - Really Simple Weather Script

Just customized the script so that it uses wget and awk (both I prefer big_smile ). Plus it reads weather condition for Currently, Today and Tomorrow.

# !/usr/bin/bash
METRIC=1 #Should be 0 or 1; 0 for F, 1 for C
if [ -z $1 ]; then
    echo "USAGE: weather.sh <locationcode>"
    exit 0;
fi

wget -q http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=$1 -O - | awk \
'/Currently:/ {CurWeather=$0}
/[0-9] Forecast<\/title>/ {nr=NR+5}
NR==nr    {postIndx[++x]=$0}
# x>2    {exit}
END{
    split(CurWeather,tmp,"Currently: ")
    split(tmp[2],tmp1,"<")
    CurWeather=sprintf("%s",tmp1[1])
    sub(":",",",CurWeather)
    for(x in postIndx){
    split(postIndx[x],tmp,";|&")
    split(tmp[1],tmp,">")
    split(tmp[2],statement," C ") # substitute C for F if metric differs
    split(tmp[2],temp)
    forecast[++y]=sprintf("%d-%dC %-15s",temp[5],temp[2],statement[3])
    }
    printf("WEATHER: %s\n%s\n%s",CurWeather,forecast[1],forecast[2])
}'

Last edited by kaikaizi (2010-05-11 19:04:32)

Offline

#46 2010-05-11 14:51:26

fflarex
Member
Registered: 2007-09-15
Posts: 466

Re: Conky - Really Simple Weather Script

kaikaizi wrote:

Just customized the script so that it uses wget and awk (both I prefer big_smile ), and you don't need to install curl and perl.

How in the world do you get by in arch without perl?

Offline

#47 2010-05-11 17:32:36

kaikaizi
Member
Registered: 2010-05-11
Posts: 10

Re: Conky - Really Simple Weather Script

fflarex wrote:
kaikaizi wrote:

Just customized the script so that it uses wget and awk (both I prefer big_smile ), and you don't need to install curl and perl.

How in the world do you get by in arch without perl?

You're right. I am just more comfortable using awk smile

Offline

#48 2010-06-13 13:09:56

orphius1970
Member
From: Modesto (HELL) California
Registered: 2009-02-27
Posts: 151

Re: Conky - Really Simple Weather Script

removed

Last edited by orphius1970 (2010-06-14 06:35:40)


AMD Phenomx3, 4gb ram, Nvidia Gforce 9400gt,
MSI K9N2 Diamond Motherboard, Arch x86_64

Offline

#49 2011-04-27 16:44:29

webmasteryoda
Member
From: Serbia
Registered: 2010-03-20
Posts: 115
Website

Re: Conky - Really Simple Weather Script

kaikaizi wrote:

Just customized the script so that it uses wget and awk (both I prefer big_smile ). Plus it reads weather condition for Currently, Today and Tomorrow.

# !/usr/bin/bash
METRIC=1 #Should be 0 or 1; 0 for F, 1 for C
if [ -z $1 ]; then
    echo "USAGE: weather.sh <locationcode>"
    exit 0;
fi

wget -q http://rss.accuweather.com/rss/liveweather_rss.asp\?metric\=${METRIC}\&locCode\=$1 -O - | awk \
'/Currently:/ {CurWeather=$0}
/[0-9] Forecast<\/title>/ {nr=NR+5}
NR==nr    {postIndx[++x]=$0}
# x>2    {exit}
END{
    split(CurWeather,tmp,"Currently: ")
    split(tmp[2],tmp1,"<")
    CurWeather=sprintf("%s",tmp1[1])
    sub(":",",",CurWeather)
    for(x in postIndx){
    split(postIndx[x],tmp,";|&")
    split(tmp[1],tmp,">")
    split(tmp[2],statement," C ") # substitute C for F if metric differs
    split(tmp[2],temp)
    forecast[++y]=sprintf("%d-%dC %-15s",temp[5],temp[2],statement[3])
    }
    printf("WEATHER: %s\n%s\n%s",CurWeather,forecast[1],forecast[2])
}'

This is how it looks on my desktop:
WEATHER: Partly Sunny, 18C
10-21C Partly sunny
9-18C Rather cloudy, showers around

I wish it to looks like this:
WEATHER:
Now: 18C - Partly sunny
Today: 10-21C - Partly sunny
Tomorrow: 9-18C - Rather cloudy, showers around

How to achieve this?

Last edited by webmasteryoda (2011-04-27 16:45:50)

Offline

#50 2011-04-27 16:50:28

skunktrader
Member
From: Brisbane, Australia
Registered: 2010-02-14
Posts: 1,316

Re: Conky - Really Simple Weather Script

Change the last line to

printf("WEATHER:\nNow: %s\nToday: %s\nTomorrow: %s",CurWeather,forecast[1],forecast[2])

Offline

Board footer

Powered by FluxBB