Shell Script in GeekTool trouble ...

Joined
May 19, 2009
Messages
8,428
Reaction score
295
Points
83
Location
Waiting for a mate . . .
Your Mac's Specs
21" iMac 2.9Ghz 16GB RAM - 10.11.3, iPhone6s & iPad Air 2 - iOS 9.2.1, ATV 4Th Gen tvOS, ATV3
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 :)
 
Joined
Mar 17, 2008
Messages
6,879
Reaction score
191
Points
63
Location
Tucson, AZ
Your Mac's Specs
Way... way too many specs to list.
Ok, lets break this down....

Code:
curl [url=http://m.wund.com/global/stations/94975.html]Weather Underground (Mobile)[/url]
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.
 
Joined
Mar 17, 2008
Messages
6,879
Reaction score
191
Points
63
Location
Tucson, AZ
Your Mac's Specs
Way... way too many specs to list.
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°C</td>
 
OP
TattooedMac
Joined
May 19, 2009
Messages
8,428
Reaction score
295
Points
83
Location
Waiting for a mate . . .
Your Mac's Specs
21" iMac 2.9Ghz 16GB RAM - 10.11.3, iPhone6s & iPad Air 2 - iOS 9.2.1, ATV 4Th Gen tvOS, ATV3
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 :)

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°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
 
Joined
Mar 17, 2008
Messages
6,879
Reaction score
191
Points
63
Location
Tucson, AZ
Your Mac's Specs
Way... way too many specs to list.
No problem, sed and awk are both really.. really... really.. useful :)
 
OP
TattooedMac
Joined
May 19, 2009
Messages
8,428
Reaction score
295
Points
83
Location
Waiting for a mate . . .
Your Mac's Specs
21" iMac 2.9Ghz 16GB RAM - 10.11.3, iPhone6s & iPad Air 2 - iOS 9.2.1, ATV 4Th Gen tvOS, ATV3
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
 
Joined
Mar 17, 2008
Messages
6,879
Reaction score
191
Points
63
Location
Tucson, AZ
Your Mac's Specs
Way... way too many specs to list.
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 :)
 
OP
TattooedMac
Joined
May 19, 2009
Messages
8,428
Reaction score
295
Points
83
Location
Waiting for a mate . . .
Your Mac's Specs
21" iMac 2.9Ghz 16GB RAM - 10.11.3, iPhone6s & iPad Air 2 - iOS 9.2.1, ATV 4Th Gen tvOS, ATV3
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
 
Joined
Mar 17, 2008
Messages
6,879
Reaction score
191
Points
63
Location
Tucson, AZ
Your Mac's Specs
Way... way too many specs to list.
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 °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.
 
OP
TattooedMac
Joined
May 19, 2009
Messages
8,428
Reaction score
295
Points
83
Location
Waiting for a mate . . .
Your Mac's Specs
21" iMac 2.9Ghz 16GB RAM - 10.11.3, iPhone6s & iPad Air 2 - iOS 9.2.1, ATV 4Th Gen tvOS, ATV3
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 °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.....
 
OP
TattooedMac
Joined
May 19, 2009
Messages
8,428
Reaction score
295
Points
83
Location
Waiting for a mate . . .
Your Mac's Specs
21" iMac 2.9Ghz 16GB RAM - 10.11.3, iPhone6s & iPad Air 2 - iOS 9.2.1, ATV 4Th Gen tvOS, ATV3
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

20091113-g5822c2bycc6sadfnm81dj8feh.jpg
 
Joined
Mar 17, 2008
Messages
6,879
Reaction score
191
Points
63
Location
Tucson, AZ
Your Mac's Specs
Way... way too many specs to list.
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 ,
 
OP
TattooedMac
Joined
May 19, 2009
Messages
8,428
Reaction score
295
Points
83
Location
Waiting for a mate . . .
Your Mac's Specs
21" iMac 2.9Ghz 16GB RAM - 10.11.3, iPhone6s & iPad Air 2 - iOS 9.2.1, ATV 4Th Gen tvOS, ATV3
Nice one !!!!

Double thumbs up mate

Cheers
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top