Mac Forums

Mac Forums (http://www.mac-forums.com/forums/)
-   OS X - Development and Darwin (http://www.mac-forums.com/forums/os-x-development-darwin/)
-   -   Shell Script in GeekTool trouble ... (http://www.mac-forums.com/forums/os-x-development-darwin/175146-shell-script-geektool-trouble.html)

TattooedMac 11-10-2009 05:57 AM

Shell Script in GeekTool trouble ...
 
Hello all.

Am a noob to this writing scripts and what not. I am ATM using GeekTool to make my active desktop and am not doing to bad.
I have been finding scripts and tweaking and playing with them to suit myself and very slowly learning the code.

My problem is the script i have for my weather is from a site on other side of the world and hasnt up to date info for where i live.

I havnt found away to make it run with my weather site i use here in Australia.
The URL other[s/ or most of the scripts are for www.wunderland.com and the code is

Code:

curl http://m.wund.com/global/stations/94975.html|sed -n '21p' | sed -e 's/<span class="nowrap"><b>//g' | sed -e 's/<\/b.*//g'
And no i havnt had any joy with the code for the use of lynx so have to use curl.

I am wanting a script so i can use www.eldersweather.com

I have played with the above mentioned and for the life of me cant do it.

When i use Elders in the script i get " <: Code used in public domain" or something to that effect.
Can anyone point me in the right direction ?? Would be greatly appreciated.

ANd i really hope this all makes sense BC as i said before im so NEW to this code thing..

Thanks in advance people :)

Dysfunction 11-10-2009 04:08 PM

Ok, lets break this down....

gets that page.

the sed -n '21p' parses out the following...

Code:

mikeMbp:~ mike$ cat wundweather.tst |sed -n '21p'
  <span class="nowrap"><b>14</b>°C</span>
mikeMbp:~ mike$

sed -e 's/<span class="nowrap"><b>//g' and sed -e 's/<\/b.*//g' are line substitution strings so the first gets us
Code:

mikeMbp:~ mike$ cat wundweather.tst |sed -n '21p'|sed -e 's/<span class="nowrap"><b>//g'
  14</b>°C</span>

and the second gets us
Code:

mikeMbp:~ mike$ cat wundweather.tst |sed -n '21p'|sed -e 's/<span class="nowrap"><b>//g'| sed -e 's/<\/b.*//g'
  14

Now, if your OTHER page is not identically laid out.. you'll have to change your sed statements to match. I have to go pick my kids up from school, I'll check when I get back and play with that one if need be.

dbnoise 11-10-2009 05:32 PM

Another way to display weather in geektool is use yweather.pl, which is a really nice script someone wrote that uses yahoo weather.
Here's a link if you want to check it out: yweather - Project Hosting on Google Code

Dysfunction 11-10-2009 05:39 PM

Ok, so.. I redid that whole thing piping things to files (which eliminated the transmission details)...


Code:

mikeMbp:~ mike$ cat wundweather.tst |sed -n '21p' |sed -e 's/<span class="nowrap"><b>//g' |sed -e 's/<\/b.*//g'
  14
mikeMbp:~ mike$ cat hobartweather.tst |sed -n '21p' |sed -e 's/<span class="nowrap"><b>//g' |sed -e 's/<\/b.*//g'
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
mikeMbp:~ mike$

so.. this should work...

Code:

curl http://www.eldersweather.com.au/tas/lower-derwent/hobart?fc=9329  |sed -n '448p' |sed -e 's/<td class="center bold">//g' |sed -e 's/&.*//g'
Code:

mikeMbp:~ mike$ cat hobartweather.tst |sed -n '448p' |sed -e 's/<td class="center bold">//g' |sed -e 's/&.*//g'
                        14.5
mikeMbp:~ mike$

edit.. how did I find the line number?
Code:

mikeMbp:~ mike$ cat -n hobartweather.tst |grep 14.5
  448                                <td class="center bold">14.5&deg;C</td>


TattooedMac 11-10-2009 05:52 PM

Quote:

Originally Posted by dbnoise (Post 940871)
Another way to display weather in geektool is use yweather.pl, which is a really nice script someone wrote that uses yahoo weather.
Here's a link if you want to check it out: yweather - Project Hosting on Google Code

Thanks db ill check this out too :)

Quote:

Originally Posted by Dysfunction (Post 940875)
Ok, so.. I redid that whole thing piping things to files (which eliminated the transmission details)...


Code:

mikeMbp:~ mike$ cat wundweather.tst |sed -n '21p' |sed -e 's/<span class="nowrap"><b>//g' |sed -e 's/<\/b.*//g'
  14
mikeMbp:~ mike$ cat hobartweather.tst |sed -n '21p' |sed -e 's/<span class="nowrap"><b>//g' |sed -e 's/<\/b.*//g'
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
mikeMbp:~ mike$

so.. this should work...

Code:

curl http://www.eldersweather.com.au/tas/lower-derwent/hobart?fc=9329  |sed -n '448p' |sed -e 's/<td class="center bold">//g' |sed -e 's/&.*//g'
Code:

mikeMbp:~ mike$ cat hobartweather.tst |sed -n '448p' |sed -e 's/<td class="center bold">//g' |sed -e 's/&.*//g'
                        14.5
mikeMbp:~ mike$

edit.. how did I find the line number?
Code:

mikeMbp:~ mike$ cat -n hobartweather.tst |grep 14.5
  448                                <td class="center bold">14.5&deg;C</td>


Bloody awesome mate.. Thank you muchly.

I ran it and it works a treat and ill use the same code to get my conditions as well :)

Ill do some work and learn from it ... Ill break down my old code and the new one produced by you and see the differences.
This is a great leaning curve and hope i become more proficient at it.

Like using my local weather site and widgets take up too much resources so AAA+++

Cheers

Dysfunction 11-10-2009 07:23 PM

No problem, sed and awk are both really.. really... really.. useful :)

TattooedMac 11-11-2009 05:00 PM

Quote:

Originally Posted by Dysfunction (Post 940922)
No problem, sed and awk are both really.. really... really.. useful :)

HAHA thanks but not having great deal of luck here. As stated before real nOOb to all this.
With being a pain in the ....... You seemed to do the code for temp with such ease, and ATM my eyes are hanging out the back of my head and all the symbols are blending together lol

Are you able to knock one up for forecast ??? If its not to much trouble.

Im a more hands on bloke and if i was sitting beside you i would and could get a better understanding of it al ... :)

with the
Code:

curl --silent -o /weather.png
maybe

If i had both working codes will be a bit easier to understand but im bushed/stuffed and lost ATM

Appreciate it once again

@ dbnoise if you read this that .png code for conditions didnt work, even running it under your Zip/Location and the link to THAT particular site was "Page Not Found"
:(

Looked at the other part of your post and i still have a bit of work to do before i can play with that... Meaning ... Being code savvy

Thank Gents

:D

Dysfunction 11-11-2009 05:59 PM

yea, I'll try and get to it this evening after work and gym.

btw, this is exactly the kind of thing I've done for a living now for over a decade (well, writing scripts etc) so after a while it becomes pretty easy, especially something like text manipulation, so it's just a matter of knowing where things are in the text :)

TattooedMac 11-11-2009 06:42 PM

Quote:

Originally Posted by Dysfunction (Post 941561)
yea, I'll try and get to it this evening after work and gym.

btw, this is exactly the kind of thing I've done for a living now for over a decade (well, writing scripts etc) so after a while it becomes pretty easy, especially something like text manipulation, so it's just a matter of knowing where things are in the text :)

Wow thought it came easy to you, considering how quickly you replied to my posts.

Its something im slowly getting into because i need a new career path that doesnt require to me so physical, ie: 18hrs a day truck driving or demolition, because im so broken now.

Appreciate it and ill study your codes and see what you have done compared to others and going into town to look for learning books on code/shell script and the such.

If you have any recommendations will take it all in heed as well..

Cheers look forward to see what you come up with.

Further to the request ... was looking for the conditions where i can use the image geeklet to update the image as and when the weather changes with the condition... If that makes any sense, and i didnt make sense before ;P
Mind you i am learning from you.. Which is great :D

Cheers

Dysfunction 11-11-2009 09:08 PM

How much of the forecasted info do you want?

btw, with all the tables that's a mess... much easier on a simpler page.. for instance.. tomorrows forecast...

Code:

mikeMbp:~ mike$ curl http://www.wunderground.com/global/stations/94975.html |sed -n 1133,1144p | sed -e 's#<[^>]*>##g'

                Thursday
                Chance of Rain.
                Partly Cloudy.
                High:
                66 &deg;F
                .
                Wind
                South
                17 mph
                .
                Chance of precipitation 30%
                (water equivalent of 0.08 in).
mikeMbp:~ mike$

oh and since we're printing line ranges.. it'll fail if it changes.

TattooedMac 11-11-2009 11:20 PM

Quote:

Originally Posted by Dysfunction (Post 941661)
How much of the forecasted info do you want?

btw, with all the tables that's a mess... much easier on a simpler page.. for instance.. tomorrows forecast...

Code:

mikeMbp:~ mike$ curl http://www.wunderground.com/global/stations/94975.html |sed -n 1133,1144p | sed -e 's#<[^>]*>##g'

                Thursday
                Chance of Rain.
                Partly Cloudy.
                High:
                66 &deg;F
                .
                Wind
                South
                17 mph
                .
                Chance of precipitation 30%
                (water equivalent of 0.08 in).
mikeMbp:~ mike$

oh and since we're printing line ranges.. it'll fail if it changes.

Nice. Really just wanting todays Temp that im using the code of yours from yesterday and i have refresh rate set at 100 sec's and in the forecast as in conditions just the ( partly cloudy ) part of it and the (partly cloudy) icon with it and changes as the conditions do. Will have the refresh rate set at 100 sec's as well.
Dont need the precipitation and wind speeds, as its not really relevant to the info im after.
Would be nice to have tomorrows outlook but not essential.

Just want to keep it as simple as possible
Make sense ?? Dont want you going out of your way !!!
Cheers

And is it good to play with these scripts in terminal.....

TattooedMac 11-13-2009 12:38 AM

Well pretty happy with myself as i have come up with this

Code:

TZ=Australia/GMT-11 date +"Sydney: %H%M Hrs - %D"
TZ=England/GMT date +"London: date %H%M Hrs - %D"
TZ=NewYork/GMT5 date +"New York: %H%M Hrs - %D"
TZ=LosAngeles/GMT8 date  +"Los Angeles: %H%M Hrs - %D"

Showing Time zones from around the world

And through a lot of looking around i have come up with this for the temp and conditions

Code:

curl --silent "http://xml.weather.yahoo.com/forecastrss?p=ASXX0057&u=c" | grep -E '(Current Conditions:|C<BR)' | sed -e 's/Current Conditions://' -e 's/<br \/>//' -e 's/<b>//' -e 's/<\/b>//' -e 's/<BR \/>//' -e 's/<description>//' -e 's/<\/description>//'
I get Partly Cloudy, 21c

Using Yahoo weather. The Elders one seemed to go beserk yesterday.

Am happy with it all ATM but cant work out how to get rid of the comma in the weather script ...

Thanks for you help though mate :)

Cheers
Screenshot

http://img.skitch.com/20091113-g5822...nm81dj8feh.jpg

Dysfunction 11-13-2009 09:18 AM

try adding | tr -d ,
to the end...
like such.
Code:

curl --silent "http://xml.weather.yahoo.com/forecastrss?p=ASXX0057&u=c" | grep -E '(Current Conditions:|C<BR)' | sed -e 's/Current Conditions://' -e 's/<br \/>//' -e 's/<b>//' -e 's/<\/b>//' -e 's/<BR \/>//' -e 's/<description>//' -e 's/<\/description>//'| tr -d ,

TattooedMac 11-13-2009 06:16 PM

Nice one !!!!
 
Double thumbs up mate

Cheers


All times are GMT -4. The time now is 06:39 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.