How to update weather script every hour?

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
stu90

How to update weather script every hour?

#1 Post by stu90 »

Hello,

i had a go at making a script to download a .txt file for local weather - i have put this in /startup to downloads on each boot, what i would like to do now is have this script automatically run every hour to download an updated weather .txt file.


Here is the script in /startup

Code: Select all

#!/bin/sh


if [ /root/EGXE.TXT ];then 
 rm /root/EGXE.TXT 
fi

wget http://weather.noaa.gov/pub/data/observations/metar/decoded/EGXE.TXT

if [ /root/Startup/EGXE.TXT ];then 
 mv EGXE.TXT /root/EGXE.TXT
fi
For the downloaded .txt file i have made another script that uses xmessage to display the content of the .txt file.

Code: Select all

#!/bin/sh 
            
xmessage -buttons "Exit" -fg "#59FF00" -bg "#000000" -title Weather -center -file /root/EGXE.TXT -timeout 10
Image

I really don't know anything about writing scripts so any help with A. writing them correctly and B. how to run the one in /startup every hour would be much appreciated.

thanks.

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#2 Post by amigo »

cron is the daemon usually used to perform actions on a schedule.

thelaptopkiller
Posts: 66
Joined: Sun 25 Oct 2009, 14:23
Location: The only place in tornado ally with no tornadoes

#3 Post by thelaptopkiller »

Well I'm a little rusty on my BASH(working on c++ now) but I think the best way would be

Code: Select all

sleep 3600

Now I can't remember wether sleep does miliseconds or not(sleep does in c++) but that should work if it does seconds

or you could always do

Code: Select all

sleep 60m
(I think)

or

Code: Select all

sleep 1h
(again I think I haven't done BASH in months now)


Hope this helps


Thelaptopkiller

stu90

#4 Post by stu90 »

Hi amigo,
I tried to set up something called crontabs this afternoon but couldn't get it to work - do you have any examples on how i may use cron in my script.

Hi thelaptopkiller,
i tried adding sleep 3600 first at top of script then at bottom but for some reason it only runs the once. :(

Off topic. Santa has just gone past out side sat in the back of a small pick up with wooden rain dears and fairy lights stuck on the side. :)

User avatar
vovchik
Posts: 1507
Joined: Tue 24 Oct 2006, 00:02
Location: Ukraine

weather

#5 Post by vovchik »

Dear guys,

Please look at this....

With kind regards,
vovchik

http://www.basic-converter.org/bweather.bac.html

User avatar
trapster
Posts: 2117
Joined: Mon 28 Nov 2005, 23:14
Location: Maine, USA
Contact:

#6 Post by trapster »

stu90

I think you can simplify to this:

Code: Select all

#!/bin/sh

if [ /root/EGXE.TXT ];then
 rm /root/EGXE.TXT
fi

wget http://weather.noaa.gov/pub/data/observations/metar/decoded/EGXE.TXT

xmessage -buttons "Exit" -fg "#59FF00" -bg "#000000" -title Weather -center -file /root/EGXE.TXT -timeout 10
Save it to /usr/local/bin as something like /usr/local/bin/weather. Make sure it is executable (right click > permissions > Yes)

Then use Menu > System > Pschedule to schedule it every hr.

If you want it at startup create a link in /root/Startup
trapster
Maine, USA

Asus eeepc 1005HA PU1X-BK
Frugal install: Slacko
Currently using full install: DebianDog

User avatar
technosaurus
Posts: 4853
Joined: Mon 19 May 2008, 01:24
Location: Blue Springs, MO
Contact:

#7 Post by technosaurus »

I used sed to remove the extraneous stuff in parenthesis, sent the wget messages to /dev/null, added a check to see if you are in X (and use echo instead of xmessage if not), as well as using the wget text directly via pipes without needing to save/remove it

Code: Select all

#!/bin/sh
show_wx() {
 [ $DISPLAY ] && BEGIN='xmessage -buttons Exit -fg #59FF00 -bg #000000 -title Weather -center' \
 && END='-timeout 10' || BEGIN=echo
 $BEGIN "`wget -O - http://weather.noaa.gov/pub/data/observations/metar/decoded/EGXE.TXT 2>/dev/null \
 |sed 's/([- a-zA-Z0-9]*)//g'`" $END
}

show_wx
while (sleep 3600) do show_wx; done
this is one that you would run as a daemon in the background such as:

show_wx &

(if you wanted to get really creative you can use Xdialog and pick an icon based on the Weather:)
Check out my [url=https://github.com/technosaurus]github repositories[/url]. I may eventually get around to updating my [url=http://bashismal.blogspot.com]blogspot[/url].

stu90

#8 Post by stu90 »

vovchik:
Thanks for script, think i need to install bacon on Lucid puppy for it to work, will look into it.
cheers.


Trapster:
I have been using Puppy pretty much exclusively for a year now and i didn't even know about Pschedule :oops: on the plus side it worked a treat and i now get update weather every hour.
thanks.

technosaurus:
Thanks for script, will make a new file and try it tonight. 8)
cheers.

Jasper

#9 Post by Jasper »

Hi again stu90,

I have a Firefox RSS feed to my BBC weather forecast (see picture for your area), but I tried your method (non-auto just typing weather in the console) and it worked fine.

My regards

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#10 Post by 01micko »

Here's the icons that you may want.. Here's a script to show how the icons can be used..

Here's a snippet that shows how Xdialog can be used

Code: Select all

 Xdialog --title "Weather" --ok-label "close" --icon /root/my-documents/weathericons/a.gif --msgbox "`cat /etc/rc.d/PUPSTATE`" 0 0
just type "Xdialog" for a list of options including geometry to control onscreen placement.. there are plenty of examples around to work out screen size so you don't have to hard code to your screen size.

That's assuming you extracted the icons to /root/my-documents and I just picked an example file on my system to show how to extract info from the file.
hth

Cheers
Attachments
example.png
(33.5 KiB) Downloaded 1019 times
Puppy Linux Blog - contact me for access

stu90

#11 Post by stu90 »

Hello Sir Jasper,

I downloaded the ubuntu version of snownews which is a text based terminal RSS reader - weather from the BBC worked great, feeds from i think omgubuntu not so good.


01micko,

That looks great, with icons as well going to download load and have a play.

cheers.

Pelo

technicians should be interested in this topic !

#12 Post by Pelo »

hum, our French and Quebec technicians should be interested in this topic !
Attachments
Meteo-Pelo.jpg
Medor provides app via terminal
(113.31 KiB) Downloaded 104 times

Post Reply