pworl curl

An iPhone client for Growl available on the App Store.
toggie
Harmless
Posts: 5
Joined: Fri Sep 04, 2009 9:53 am

pworl curl

Postby toggie » Fri Sep 04, 2009 9:58 am

hej i would like to use curl -s "http://mobile.weather.gov/port_mp_ns.php?select=1&CityName=New%20York&site=OKX&State=NY&warnzone=NYZ072" and the get that prowl to my iphone..


i know this work,, but how do i get the other info in it?
curl https://prowl.weks.net/publicapi/add -F apikey=xxxx -F application=curl -F event='Ta Da' -F description='Here We Go'

thx,, the n00b

fubaya
Harmless
Posts: 20
Joined: Sat Sep 05, 2009 3:15 am

Re: pworl curl

Postby fubaya » Sun Sep 06, 2009 3:55 am

What operating system are you using and what are you using to run curl?

I need a script to do this exact same thing so let's do it. I use Linux and the BASH shell, so I hope this helps you. Let's start with a simple script like this:

Code: Select all

#! /bin/sh
wx=`curl -s "http://mobile.weather.gov/port_mp_ns.php?select=1&CityName=New%20York&site=OKX&State=NY&warnzone=NYZ072"`

curl https://prowl.weks.net/publicapi/add -F apikey=XXX -F application=curl -F event='Ta Da' -F description="$wx"


wx is a variable which is set by running whatever is between the tick marks, in this case it is the curl -s command which gets the weather, so once the first line of the script runs the weather information you want is stored in the wx variable. You call the wx variable with $wx in the second line.

Ok, that works but it looks bad. It still has all the HTML formatting. Maybe curl can be used differently but I'm not very familiar with it and I usually use lynx or links, which are two similar command line web browsers, and the -dump switch which both have. In this case, links ends up looking nicer so I'll use links -dump.

To make it look better, here are some other options you may want to use. You can pipe one command to another like this "command | command". In this case you may want to pipe the output of the links command to something else to make it look better. The pipe and commands would be placed between the quotation mark and the tick mark in NYZ072"` like this NYZ072" | X | X`

Here are 4 commands you may want to use
sed to align the weather information to the left
grep to remove the dashes
grep to remove the "Back to previous page" line at the bottom
grep to remove both:

Code: Select all

sed 's/^[ \t]*//'
grep -v -----------------
grep -v "Back to previous page"
grep -E -v '(-----------------|Back to previous page)'


This looks a lot better:

Code: Select all

#! /bin/sh
wx=`links -dump "http://mobile.weather.gov/port_mp_ns.php?select=1&CityName=New%20York&site=OKX&State=NY&warnzone=NYZ072" | sed 's/^[ \t]*//' | grep -E -v '(-----------------|Back to previous page)'`

curl https://prowl.weks.net/publicapi/add -F apikey=188642a781970faa3a4e944c59c6994cafe7e74e -F application=curl -F event='Ta Da' -F description="$wx"


To make it even prettier, let's look at the text...
NWS Zone Forecast for:
New York (Manhattan) County, NY
Issued by: National Weather Service
New York City, NY
Last Update:
854 PM EDT SAT SEP 5 2009
__________________________________________________________________

Tonight...Mostly cloudy. ....blah blah blah


Using grep, let's only display everything below and including the line "Last Update:
854 PM EDT SAT SEP 5 2009" and put the "NWS Zone Forecast for:
New York (Manhattan) County, NY" in the curl options, so instead of the notification pop-up box showing

curl--Ta-Da
NWS Zone Forecast for:
New York (Manhattan) County, NY
Issued by: National Weather Service
New York City, NY
----

it will show up as

NWS Forecast--New York (Manhattan) County, NY
Last Update:
854 PM EDT SAT SEP 5 2009

and it will display "NWS Forecast--New York (Manhattan) County, NY" as the header when you open it in Prowl

Code: Select all

#! /bin/sh
wx=`links -dump "http://mobile.weather.gov/port_mp_ns.php?select=1&CityName=New%20York&site=OKX&State=NY&warnzone=NYZ072" | sed 's/^[ \t]*//' | grep -E -v '(-----------------|Back to previous page)' | grep -A 1000 "Last Update"`

curl https://prowl.weks.net/publicapi/add -F apikey=188642a781970faa3a4e944c59c6994cafe7e74e -F application="NWS Forecast" -F event='New York (Manhattan) County, NY' -F description="$wx"


I think I'm happy with this and hopefully there is enough info here to get it the way you want it to look on your system.

fubaya
Harmless
Posts: 20
Joined: Sat Sep 05, 2009 3:15 am

Re: pworl curl

Postby fubaya » Sun Sep 06, 2009 2:01 pm

In case anyone wonders, I realized that I left my api key in that post and changed it after I made that post.

toggie
Harmless
Posts: 5
Joined: Fri Sep 04, 2009 9:53 am

Re: pworl curl

Postby toggie » Thu Sep 10, 2009 11:40 am

just seen your post now,, i use OS X 10.6.

toggie
Harmless
Posts: 5
Joined: Fri Sep 04, 2009 9:53 am

Re: pworl curl

Postby toggie » Thu Sep 10, 2009 11:46 am

i cant get it to work on my Mac :(

fubaya
Harmless
Posts: 20
Joined: Sat Sep 05, 2009 3:15 am

Re: pworl curl

Postby fubaya » Thu Sep 10, 2009 3:35 pm

I've never used a Mac so I won't be much help. Are you able to run the script at all? Does it give an error?

toggie
Harmless
Posts: 5
Joined: Fri Sep 04, 2009 9:53 am

Re: pworl curl

Postby toggie » Thu Sep 10, 2009 4:46 pm

fubaya wrote:I've never used a Mac so I won't be much help. Are you able to run the script at all? Does it give an error?


yeah i dont think you can run those cmd on a mac :(

pogo
Harmless
Posts: 7
Joined: Sat Sep 05, 2009 11:01 am

Re: pworl curl

Postby pogo » Thu Sep 10, 2009 4:52 pm

you can install curl with MacPorts or something...

toggie
Harmless
Posts: 5
Joined: Fri Sep 04, 2009 9:53 am

Re: pworl curl

Postby toggie » Thu Sep 10, 2009 4:59 pm

pogo wrote:you can install curl with MacPorts or something...



i have curl its says unknow token at wx=` its this it points out= ` (dont know the name)

fubaya
Harmless
Posts: 20
Joined: Sat Sep 05, 2009 3:15 am

Re: pworl curl

Postby fubaya » Fri Sep 11, 2009 2:49 am

Macs use Applescript but my example was a BASH script. I don't know if it's worth it to you or if it would work the way you want it to, but you can install bash on a Mac.

That pretty much used up all my Mac knowledge.

User avatar
AssetBurned
Muffin
Posts: 27
Joined: Sat Nov 07, 2009 5:02 pm

Re: pworl curl

Postby AssetBurned » Tue Nov 17, 2009 3:52 am

Bash ist part of Darwin, which is an BSD operating system. And Darwin is the foundation of what you see if you boot up an OS X system.
curl is also part of your default 10.x Mac OS installation... But from my point of view someone forgot to allow curl make use of HTTPS connections in Snow Leopard (10.6) i can use curl to connect to a HTTPS server on my Leopard machine (10.5) :-/

User avatar
AssetBurned
Muffin
Posts: 27
Joined: Sat Nov 07, 2009 5:02 pm

Re: pworl curl

Postby AssetBurned » Tue Nov 17, 2009 4:00 am

hm not excatly right...

check out this script:

Code: Select all

tell application "Finder"
   set apikey to "XXX" as string
   do shell script ("curl -k https://prowl.weks.net/publicapi/add -F apikey=\"" & apikey & "\" -F application=\"fancyapp\" -F description=\"test\" ")
end tell

just replace the XXX with the apikey you have.


Return to “Prowl”

Who is online

Users browsing this forum: No registered users