Any example Twitter API -> Prowl code out there?

An iPhone client for Growl available on the App Store.
jaseone
Harmless
Posts: 6
Joined: Sat Jul 11, 2009 2:01 am

Any example Twitter API -> Prowl code out there?

Postby jaseone » Sat Jul 11, 2009 2:05 pm

Has anyone gone to the trouble of writing a script (preferably PHP but I'll take anything) to interface Twitter Replies & DMs with Prowl to save me reinventing the wheel?

PS. Obviously this would be easy to do with the likes of Tweetie plus Growl but I only have a laptop and not a computer that is always running so would prefer something server side

User avatar
zac
Cocoaforge Admin
Posts: 1518
Joined: Sun Mar 27, 2005 3:19 pm
Contact:

Re: Any example Twitter API -> Prowl code out there?

Postby zac » Sat Jul 11, 2009 2:57 pm

I haven't seen anybody do so, but there's Twitter libraries for a whole slew of languages, and Prowl libraries for PHP, Python, Perl and Ruby (that I know, might be more!)

jaseone
Harmless
Posts: 6
Joined: Sat Jul 11, 2009 2:01 am

Re: Any example Twitter API -> Prowl code out there?

Postby jaseone » Sun Jul 12, 2009 2:34 pm

I was just being lazy... I hacked up something yesterday to push Twitter replies using PHP Twitter, if anyone is interested in the code let me know and I'll clean it up so I can post it.

rix501
Harmless
Posts: 4
Joined: Sun Jul 12, 2009 6:49 pm

Re: Any example Twitter API -> Prowl code out there?

Postby rix501 » Sun Jul 12, 2009 7:47 pm

I was thinking of doing something similar to this. Will really appreciate if you post your code to see what you have. Thanks!

balu
Harmless
Posts: 8
Joined: Thu Jul 09, 2009 10:50 pm

Re: Any example Twitter API -> Prowl code out there?

Postby balu » Mon Jul 13, 2009 1:32 pm

I've got an perl script doing this,
its very easy using twitter and prowl libary
script is posted http://www.ohnekontur.de/index.php/2009/07/13/twitter-push-notifications-aufs-iphone-mit-prowl/ there

jaseone
Harmless
Posts: 6
Joined: Sat Jul 11, 2009 2:01 am

Re: Any example Twitter API -> Prowl code out there?

Postby jaseone » Mon Jul 13, 2009 5:31 pm

balu wrote:I've got an perl script doing this,
its very easy using twitter and prowl libary
script is posted http://www.ohnekontur.de/index.php/2009/07/13/twitter-push-notifications-aufs-iphone-mit-prowl/ there


Isn't that code missing a file handle in the first file open call? My PHP code is essentially the same as that:

Code: Select all

<?php
include_once('class.twitter.php');
include "class.prowl.php";
$t = new Twitter;
$t->username = 'yourusername';
$t->password = 'yourpassword;

$prowl = new Prowl("yourusername", "yourpasword", "Twitter");

$last_reply_file = ("last_reply.txt");
$last_reply = file($last_reply_file);
//echo 'from file: ', $last_reply[0],'<br>';

$data = $t->getReplies('','',$last_reply[0]);

//print_r($data);

//echo 'from array: ',$data[0]->id,'<br';

if(array_key_exists(0,$data)){
   $last_reply_id = $data[0]->id;

   echo $last_reply_id,'<br';
   $fp = fopen($last_reply_file , "w");
   fputs($fp , $last_reply_id);
   fclose($fp);

   foreach(array_reverse($data) as $tweet) {
      $prowl_format = $tweet->user->screen_name.": ".$tweet->text;
      //echo $prowl_format, "<br>";
      $result = $prowl->send("New reply",$prowl_format);   
      /*uncomment for debugging
         echo $tweet->id,' : ';
      echo $tweet->user->screen_name, ": ";
      echo $tweet->text;
      echo "<br><br>";
      */
   }
}

?>

rix501
Harmless
Posts: 4
Joined: Sun Jul 12, 2009 6:49 pm

Re: Any example Twitter API -> Prowl code out there?

Postby rix501 » Tue Jul 14, 2009 1:49 am

I didn't use the class.prowl.php lib since it didn't use the API key, instead I used ProwlPHP.php lib which is supplied in the Prowl website. What I was wondering if it was possible to have real "push" notifications from Twitter, since all I can think right now is of using cron to check every few minutes. Any ideas?

User avatar
zac
Cocoaforge Admin
Posts: 1518
Joined: Sun Mar 27, 2005 3:19 pm
Contact:

Re: Any example Twitter API -> Prowl code out there?

Postby zac » Tue Jul 14, 2009 1:54 am

There is a Twitter streaming API, or at least a user in another thread set up a script using it. From what I've read, though, it's an alpha API that has been changing quite a bit.

balu
Harmless
Posts: 8
Joined: Thu Jul 09, 2009 10:50 pm

Re: Any example Twitter API -> Prowl code out there?

Postby balu » Tue Jul 14, 2009 12:10 pm

jaseone wrote:
balu wrote:I've got an perl script doing this,
its very easy using twitter and prowl libary
script is posted http://www.ohnekontur.de/index.php/2009/07/13/twitter-push-notifications-aufs-iphone-mit-prowl/ there


Isn't that code missing a file handle in the first file open call? My PHP code is essentially the same as that:


oh damn your right i didn't escape the < > ... shuld be corrected

Bailey
Harmless
Posts: 5
Joined: Sun Feb 18, 2007 9:12 pm

Re: Any example Twitter API -> Prowl code out there?

Postby Bailey » Wed Jul 15, 2009 12:14 pm

I am that user.

Code: Select all

#!/usr/bin/env ruby

require 'net/http'
require 'rubygems'
require 'json'
require 'prowl'

prowl_api_key = 'APIKEY'

url = URI.parse("http://stream.twitter.com/track.json")

request = Net::HTTP::Post.new(url.path)
request.basic_auth 'USERNAME', 'PASSWORD'
request.set_form_data({'track' => '@USERNAME'})
http = Net::HTTP.new(url.host, url.port)
buffer = ''
http.request(request) do |res|
  res.read_body do |chunk|
    buffer = buffer + chunk
    if buffer.include? "\r" then
      buffer.split("\r").each do |status|
        if status.include? '{' then
          json = JSON.parse(status)
          Prowl.send(prowl_api_key, {
            :application => "Twitter Mention",
            :event => "from @" + json['user']['screen_name'],
            :description => json['text']
          })
        end
      end
      buffer = ''
    end
  end
end


My Ruby skills are weak, and this was knocked up in about 10 minutes, so go easy on me! It doesn't handle disconnects, although I've only suffered around 1 a day. I just use a cron job to restart it if it goes down. I'd like to daemonise it, and re-connect/fail gracefully as specified in the API.

vulcanfk
Harmless
Posts: 2
Joined: Sun Sep 13, 2009 7:01 pm

Re: Any example Twitter API -> Prowl code out there?

Postby vulcanfk » Sun Sep 13, 2009 7:08 pm

Bailey,
Trying to use your script. I replaced the authentication info and APIKEY with my information. I start up the script, and as soon as I get a mention, it gives me the following error

Code: Select all

twitter.rb:24:in `send': undefined method `<api key removed>' for Prowl:Class (NoMethodError)


Any ideas?

User avatar
tofumatt
Harmless
Posts: 20
Joined: Thu Aug 20, 2009 1:48 am
Location: Halifax, Nova Scotia, Canada
Contact:

Re: Any example Twitter API -> Prowl code out there?

Postby tofumatt » Mon Sep 14, 2009 2:35 am

Prey Fetcher does this for you, albeit at five minutes intervals. Prey Fetcher is written in Rails, so the Prowl code behind Prey Fetcher is up at http://github.com/tofumatt/ruby-prowl. The code works quite well, and I think is pretty easy to use.

vulcanfk
Harmless
Posts: 2
Joined: Sun Sep 13, 2009 7:01 pm

Re: Any example Twitter API -> Prowl code out there?

Postby vulcanfk » Tue Sep 15, 2009 1:11 am

I'm actually using PreyFetcher atm. I think 5 minutes is a little slow sometimes, so I was looking to use the streaming API. Looks like TwitterFon pro just added push notifications though, so I might just switch to that. Thanks


Return to “Prowl”

Who is online

Users browsing this forum: No registered users