Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 23 Apr 2014, 13:34
All times are UTC - 4
 Forum index » Off-Topic Area » Programming
How to update weather script every hour?
Post new topic   Reply to topic View previous topic :: View next topic
Page 1 of 1 [11 Posts]  
Author Message
stu90


Joined: 25 Feb 2010
Posts: 1401
Location: England. Dell Inspiron 1501. Dpup

PostPosted: Mon 20 Dec 2010, 09:57    Post subject:  How to update weather script every hour?  

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:
#!/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:
#!/bin/sh
           
xmessage -buttons "Exit" -fg "#59FF00" -bg "#000000" -title Weather -center -file /root/EGXE.TXT -timeout 10




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.
Back to top
View user's profile Send private message 
amigo

Joined: 02 Apr 2007
Posts: 2171

PostPosted: Mon 20 Dec 2010, 11:26    Post subject:  

cron is the daemon usually used to perform actions on a schedule.
Back to top
View user's profile Send private message 
thelaptopkiller

Joined: 25 Oct 2009
Posts: 67
Location: The only place in tornado ally with no tornadoes

PostPosted: Mon 20 Dec 2010, 11:46    Post subject:  

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

Code:
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:
sleep 60m

(I think)

or

Code:
sleep 1h

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


Hope this helps


Thelaptopkiller
Back to top
View user's profile Send private message 
stu90


Joined: 25 Feb 2010
Posts: 1401
Location: England. Dell Inspiron 1501. Dpup

PostPosted: Mon 20 Dec 2010, 14:54    Post subject:  

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. Sad

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. Smile
Back to top
View user's profile Send private message 
vovchik


Joined: 23 Oct 2006
Posts: 1285
Location: Ukraine

PostPosted: Mon 20 Dec 2010, 15:44    Post subject: weather  

Dear guys,

Please look at this....

With kind regards,
vovchik

http://www.basic-converter.org/bweather.bac.html
Back to top
View user's profile Send private message 
trapster


Joined: 28 Nov 2005
Posts: 1997
Location: Maine, USA

PostPosted: Mon 20 Dec 2010, 18:22    Post subject:  

stu90

I think you can simplify to this:
Code:
#!/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: Puppeee4.31 + 1.0, Puppy4.10 + Lupu52
Currently using Slacko AND lupu52 w/ fluxbox
Back to top
View user's profile Send private message Visit poster's website 
technosaurus


Joined: 18 May 2008
Posts: 4134

PostPosted: Mon 20 Dec 2010, 20:59    Post subject:  

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:
#!/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:)

_________________
Web Programming - Pet Packaging 100 & 101
Back to top
View user's profile Send private message 
stu90


Joined: 25 Feb 2010
Posts: 1401
Location: England. Dell Inspiron 1501. Dpup

PostPosted: Tue 21 Dec 2010, 14:37    Post subject:  

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 Embarassed 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. Cool
cheers.
Back to top
View user's profile Send private message 
Jasper


Joined: 25 Apr 2010
Posts: 1034
Location: England

PostPosted: Tue 21 Dec 2010, 18:30    Post subject:  

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
screenshot.24.jpg
 Description   
 Filesize   245.03 KB
 Viewed   290 Time(s)

screenshot.24.jpg

Back to top
View user's profile Send private message 
01micko


Joined: 11 Oct 2008
Posts: 7547
Location: qld

PostPosted: Wed 22 Dec 2010, 00:44    Post subject:  

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:
 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
example.png
 Description   
 Filesize   33.5 KB
 Viewed   861 Time(s)

example.png


_________________
Woof Mailing List | keep the faith Cool |
Back to top
View user's profile Send private message Visit poster's website 
stu90


Joined: 25 Feb 2010
Posts: 1401
Location: England. Dell Inspiron 1501. Dpup

PostPosted: Fri 24 Dec 2010, 08:52    Post subject:  

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.
Back to top
View user's profile Send private message 
Display posts from previous:   Sort by:   
Page 1 of 1 [11 Posts]  
Post new topic   Reply to topic View previous topic :: View next topic
 Forum index » Off-Topic Area » Programming
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.0711s ][ Queries: 12 (0.0062s) ][ GZIP on ]