New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Shell Script in GeekTool trouble ...


Post Reply New Thread Subscribe

 
Thread Tools
TattooedMac

 
TattooedMac's Avatar
 
Member Since: May 19, 2009
Location: Waiting for a mate . . .
Posts: 7,809
TattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant future
Mac Specs: 21" iMac 2.9Ghz 10.9.4 13"MBP 2.9Ghz i7 Yosemite 10.10 ~ iPhone5 iOS 8 ~ iPad Mini iOS 8 ~ ATV3 6.1

TattooedMac is offline
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

CogFrog Studio's ~ Photography, Apps and Web Development
Dont forget to use the Reputation System if someone has helped you out !!!
Arguing with a zealot is only slightly easier than tunneling through a mountain with your forehead!!!!!
QUOTE Thanks
Dysfunction

 
Dysfunction's Avatar
 
Member Since: Mar 17, 2008
Location: Tucson, AZ
Posts: 6,638
Dysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant future
Mac Specs: 2008 and 2011 15" mbps, late 11 iMac, iPhone 4s, and too many ipods and other stuff

Dysfunction is offline
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.

mike
This machine kills fascists
Got # ? phear the command line!
QUOTE Thanks
dbnoise

 
dbnoise's Avatar
 
Member Since: Dec 21, 2008
Posts: 314
dbnoise will become famous soon enough

dbnoise is offline
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
QUOTE Thanks
Dysfunction

 
Dysfunction's Avatar
 
Member Since: Mar 17, 2008
Location: Tucson, AZ
Posts: 6,638
Dysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant future
Mac Specs: 2008 and 2011 15" mbps, late 11 iMac, iPhone 4s, and too many ipods and other stuff

Dysfunction is offline
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>

mike
This machine kills fascists
Got # ? phear the command line!
QUOTE Thanks
TattooedMac

 
TattooedMac's Avatar
 
Member Since: May 19, 2009
Location: Waiting for a mate . . .
Posts: 7,809
TattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant future
Mac Specs: 21" iMac 2.9Ghz 10.9.4 13"MBP 2.9Ghz i7 Yosemite 10.10 ~ iPhone5 iOS 8 ~ iPad Mini iOS 8 ~ ATV3 6.1

TattooedMac is offline
Quote:
Originally Posted by dbnoise View Post
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 View Post
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

CogFrog Studio's ~ Photography, Apps and Web Development
Dont forget to use the Reputation System if someone has helped you out !!!
Arguing with a zealot is only slightly easier than tunneling through a mountain with your forehead!!!!!
QUOTE Thanks
Dysfunction

 
Dysfunction's Avatar
 
Member Since: Mar 17, 2008
Location: Tucson, AZ
Posts: 6,638
Dysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant future
Mac Specs: 2008 and 2011 15" mbps, late 11 iMac, iPhone 4s, and too many ipods and other stuff

Dysfunction is offline
No problem, sed and awk are both really.. really... really.. useful

mike
This machine kills fascists
Got # ? phear the command line!
QUOTE Thanks
TattooedMac

 
TattooedMac's Avatar
 
Member Since: May 19, 2009
Location: Waiting for a mate . . .
Posts: 7,809
TattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant future
Mac Specs: 21" iMac 2.9Ghz 10.9.4 13"MBP 2.9Ghz i7 Yosemite 10.10 ~ iPhone5 iOS 8 ~ iPad Mini iOS 8 ~ ATV3 6.1

TattooedMac is offline
Quote:
Originally Posted by Dysfunction View Post
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


CogFrog Studio's ~ Photography, Apps and Web Development
Dont forget to use the Reputation System if someone has helped you out !!!
Arguing with a zealot is only slightly easier than tunneling through a mountain with your forehead!!!!!
QUOTE Thanks
Dysfunction

 
Dysfunction's Avatar
 
Member Since: Mar 17, 2008
Location: Tucson, AZ
Posts: 6,638
Dysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant future
Mac Specs: 2008 and 2011 15" mbps, late 11 iMac, iPhone 4s, and too many ipods and other stuff

Dysfunction is offline
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

mike
This machine kills fascists
Got # ? phear the command line!
QUOTE Thanks
TattooedMac

 
TattooedMac's Avatar
 
Member Since: May 19, 2009
Location: Waiting for a mate . . .
Posts: 7,809
TattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant future
Mac Specs: 21" iMac 2.9Ghz 10.9.4 13"MBP 2.9Ghz i7 Yosemite 10.10 ~ iPhone5 iOS 8 ~ iPad Mini iOS 8 ~ ATV3 6.1

TattooedMac is offline
Quote:
Originally Posted by Dysfunction View Post
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
Mind you i am learning from you.. Which is great

Cheers

CogFrog Studio's ~ Photography, Apps and Web Development
Dont forget to use the Reputation System if someone has helped you out !!!
Arguing with a zealot is only slightly easier than tunneling through a mountain with your forehead!!!!!
QUOTE Thanks
Dysfunction

 
Dysfunction's Avatar
 
Member Since: Mar 17, 2008
Location: Tucson, AZ
Posts: 6,638
Dysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant future
Mac Specs: 2008 and 2011 15" mbps, late 11 iMac, iPhone 4s, and too many ipods and other stuff

Dysfunction is offline
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.

mike
This machine kills fascists
Got # ? phear the command line!
QUOTE Thanks
TattooedMac

 
TattooedMac's Avatar
 
Member Since: May 19, 2009
Location: Waiting for a mate . . .
Posts: 7,809
TattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant future
Mac Specs: 21" iMac 2.9Ghz 10.9.4 13"MBP 2.9Ghz i7 Yosemite 10.10 ~ iPhone5 iOS 8 ~ iPad Mini iOS 8 ~ ATV3 6.1

TattooedMac is offline
Quote:
Originally Posted by Dysfunction View Post
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.....

CogFrog Studio's ~ Photography, Apps and Web Development
Dont forget to use the Reputation System if someone has helped you out !!!
Arguing with a zealot is only slightly easier than tunneling through a mountain with your forehead!!!!!
QUOTE Thanks
TattooedMac

 
TattooedMac's Avatar
 
Member Since: May 19, 2009
Location: Waiting for a mate . . .
Posts: 7,809
TattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant future
Mac Specs: 21" iMac 2.9Ghz 10.9.4 13"MBP 2.9Ghz i7 Yosemite 10.10 ~ iPhone5 iOS 8 ~ iPad Mini iOS 8 ~ ATV3 6.1

TattooedMac is offline
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


CogFrog Studio's ~ Photography, Apps and Web Development
Dont forget to use the Reputation System if someone has helped you out !!!
Arguing with a zealot is only slightly easier than tunneling through a mountain with your forehead!!!!!
QUOTE Thanks
Dysfunction

 
Dysfunction's Avatar
 
Member Since: Mar 17, 2008
Location: Tucson, AZ
Posts: 6,638
Dysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant futureDysfunction has a brilliant future
Mac Specs: 2008 and 2011 15" mbps, late 11 iMac, iPhone 4s, and too many ipods and other stuff

Dysfunction is offline
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 ,

mike
This machine kills fascists
Got # ? phear the command line!
QUOTE Thanks
TattooedMac

 
TattooedMac's Avatar
 
Member Since: May 19, 2009
Location: Waiting for a mate . . .
Posts: 7,809
TattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant futureTattooedMac has a brilliant future
Mac Specs: 21" iMac 2.9Ghz 10.9.4 13"MBP 2.9Ghz i7 Yosemite 10.10 ~ iPhone5 iOS 8 ~ iPad Mini iOS 8 ~ ATV3 6.1

TattooedMac is offline
Double thumbs up mate

Cheers

CogFrog Studio's ~ Photography, Apps and Web Development
Dont forget to use the Reputation System if someone has helped you out !!!
Arguing with a zealot is only slightly easier than tunneling through a mountain with your forehead!!!!!
QUOTE Thanks

Post Reply New Thread Subscribe


« php can't connect to mysql | Apple Script »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Geektool script forces mail to stay open jmullenberg OS X - Apps and Games 1 09-27-2009 10:01 AM
Shell Script Address Book Mbengi Bongi OS X - Development and Darwin 0 04-28-2009 03:02 PM
Terminal.app/bash: Creating An Executable Shell Script ebay Running Windows (or anything else) on your Mac 7 04-28-2008 06:43 PM
shell script xml MrGecko OS X - Development and Darwin 4 10-03-2006 07:44 AM
Shell Script on Desktop starrin OS X - Operating System 2 07-28-2004 11:25 AM

All times are GMT -4. The time now is 01:58 AM.

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

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?