Prowl RSS Reader (And multiple API keys help!)

An iPhone client for Growl available on the App Store.
BeauGiles
Harmless
Posts: 8
Joined: Tue Jul 14, 2009 12:21 pm

Prowl RSS Reader (And multiple API keys help!)

Postby BeauGiles » Tue Jul 14, 2009 12:59 pm

UPDATE 17/7/09 - Project changed to rss2prowl - more info in this thread: http://forums.cocoaforge.com/viewtopic.php?f=45&t=20490

Using the ProwlPHP library, I've started putting together a RSS reader;

Code: Select all

<?php
include('ProwlPHP.php');
 
$prowl = new Prowl('PASTEAPIKEYHERE');

  $xmlString = file_get_contents("http://path.to/your/feed.xml");

  $xml = simplexml_load_string($xmlString);

$linebreak = $item->description;
echo str_replace("<br />","\n",$linebreak);

    foreach ($xml->channel->item as $item) {
$prowl->push(array(
                'application'=>'RSS Reader',
                'event'=>$item->title . '',
                'description'=>$item->link . '',
                'priority'=>0,
            ),true);
    }
?>


You'd be able to hit this with a cron however often you want to poll your RSS feed. One thing that needs work is caching; at the moment it'll post *all* the items in the feed *every* time the script is run. If anyone can help me with some sort of caching support (I saw in the 'what are you using the api for' thread that someone was just giving cron a command to run that retrieved the feed, cache'd it and only sent it to Prowl if there were any changes;

Code: Select all

*/30 * * * * mv /tmp/exweath_new.txt /tmp/exweath_old.txt; curl -s http://www.weather.gov/alerts-beta/wwaatmget.php?x=TXZ103|grep '<summary>'|awk -F'\.\.\.' '{print $2}' > /tmp/exweath_new.txt; if ! diff /tmp/exweath_new.txt /tmp/exweath_old.txt ; then /home/acrollet/bin/prowl.pl -apikeyfile=/home/acrollet/.prowlapikey -application='Denton County' -notification="`cat /tmp/exweath_new.txt`" -priority=1 -event='severe weather'; fi

If somebody could show me how to implement something similar I'd love you forever.

I'm also having trouble removing html code from the description, which is why I'm currently displaying the link as the description. I'll have to keep working on this unless somebody has any suggestions?

One more thing - Multiple API key support? This would be a great addition to my blog (and well, anyone else who wants to push notifications to users of their feed) if visitors could simply paste in their API key, which would then either be appended to a text file (quick and dirty), or placed in a database (more elegant, and possibly enables the user to remove themselves later if they wish) - can this be done in Prowl's API / ProwlPHP, and how?

Thanks everybody in advance; looking forward to your input. :-)
-Beau
Last edited by BeauGiles on Fri Jul 17, 2009 6:33 am, edited 1 time in total.

parlar
Harmless
Posts: 9
Joined: Tue Jul 14, 2009 3:23 pm

Re: Prowl RSS Reader (And multiple API keys help!)

Postby parlar » Tue Jul 14, 2009 3:25 pm

I have an RSS client done and working quite nicely. All I did was take the program rss2email, and modified it so it sent me Prowl notifications instead of email (using a modified prowlpy from github) . I'll try to get it up on github soon, but it's really easy to make the changes yourself.

BeauGiles
Harmless
Posts: 8
Joined: Tue Jul 14, 2009 12:21 pm

Re: Prowl RSS Reader (And multiple API keys help!)

Postby BeauGiles » Tue Jul 14, 2009 5:23 pm

parlar wrote:I have an RSS client done and working quite nicely. All I did was take the program rss2email, and modified it so it sent me Prowl notifications instead of email (using a modified prowlpy from github) . I'll try to get it up on github soon, but it's really easy to make the changes yourself.

Thanks for the idea!
I've downloaded magpierss as I've had it working with it emailing stuff to me before, and now it's better than my previous implementation :p

Code: Select all

<?php
include('classes/ProwlPHP.php');
require_once('classes/magpie/rss_fetch.inc');
$prowl = new Prowl('YOURAPIKEY');
$rss = fetch_rss('http://url.to/your/feed.xml');
$items = array_slice($rss->items, 0);

foreach ($items as $item){
      $id = $item['guid'];
                //We're going to need a unique ASCII identifier for each item later, so we'll use md5 to get one
      $itemhash = md5($id);
      $link = $item['link'];
      $subject = $item['title'];
      $subject = str_replace("?"," ",$subject);
      $subject = str_replace("&#8217;","'",$subject);
      $subject = str_replace("&#8220;","\"",$subject);
      $subject = str_replace("&#8221;","\"",$subject);
      $description = $item['content']['encoded'];
      $description = str_replace("&#8217;","'",$description);
      $description = str_replace("&#8220;","\"",$description);
      $description = str_replace("&#8221;","\"",$description);
      //Build the body with a link to the real page and the article itself
                $body = "$link \n $description \n";

           //Check to see if we've already sent this item
      if(file_exists("cache/$itemhash")){
         print("Already sent item: $subject<br>");
      } else {

$prowl->push(array(
                'application'=>'RSS Reader',
                'event'=>$subject . '',
                'description'=>$body . '',
                'priority'=>0,
            ),true);
         touch("cache/$itemhash");
      }
}
?>


Magpie generates an md5 and puts it in the /cache directory for every item, so it can compare items in the feed to items already in the cache directory, therefore not posting the same thing twice! :-)

But my question RE: Multiple API keys remain; can I simply add another $prowl = new Prowl('YOURAPIKEY'); line in and it'll work just peachy?

eg;

Code: Select all

$prowl = new Prowl('YOURAPIKEY');
$prowl = new Prowl('YOURAPIKEY2');
$prowl = new Prowl('YOURAPIKEY3');
$prowl = new Prowl('YOURAPIKEY4');
$prowl = new Prowl('YOURAPIKEY5');

And they'll all get the same notifications? Or must I implement this in a different way?

briandunnington
Muffin
Posts: 31
Joined: Fri Mar 14, 2008 10:30 pm

Re: Prowl RSS Reader (And multiple API keys help!)

Postby briandunnington » Tue Jul 14, 2009 6:14 pm

you cant just add multiple apikeys and have it work.

you could, however, loop through the apikeys and send a notification to Prowl for each. you will have to keep in mind api usage limits though (not sure if it is limited by ip address or by apikey).

parlar
Harmless
Posts: 9
Joined: Tue Jul 14, 2009 3:23 pm

Re: Prowl RSS Reader (And multiple API keys help!)

Postby parlar » Tue Jul 14, 2009 6:25 pm

briandunnington wrote:you cant just add multiple apikeys and have it work.

you could, however, loop through the apikeys and send a notification to Prowl for each. you will have to keep in mind api usage limits though (not sure if it is limited by ip address or by apikey).


From the FAQ:
The Prowl servers have a rate limit of 1000 notifications per hour from an IP address.


Return to “Prowl”

Who is online

Users browsing this forum: No registered users