Lance Wicks
Kiwi,
Judoka,
Geek,
Husband
Daddy!

JudoGeek Blog

TwitterGrowl - A perl hack to get Growl like alerts in Windoze. 

* UPdated with new code HERE http://www.lancewicks.com/blog/index.ph ... 903-202313

[Updated: June 11th 2008 to include proper use of Twitter API]

I love Twitter, I love my Mac, I love Growl, I love TwitterPod and how it pops my Twitter updates in Growl alerts.
I have a Windows machine, I don't love my Windows machine. :(
It does not have Growl, I can't put twitterpod on it. :(

It does have Perl!!! :)
And it recently got Snarl, a free piece of software that aims to be a Growl equivalent for Windows.
So I decided to put the two together and try and get Growl type alerts working.

Below is a small Perl script I wrote, yes ugly, yes needs some experts to revise it, yes I could use XML::RSS to parse it better.
I have put a bunch of comments in it to make it clearer what is happening... hopefully.

Before running the Perl, you'll need to install Perl, Growl Snarl AND Snarl_cmd all the links are below the script itself.

---

#First up load the relevant modules some are from CPAN
use XML::Simple;
use Array::Diff;
use Data::Dumper;
use IPC::Open3;
use LWP::UserAgent;

# These two are as per Damian Conways Perl Best Practices and replaces $| =1;
use English qw( -no_match_vars );
local $OUTPUT_AUTOFLUSH = 1;

# So a scaler to hold my Twitter feed Url (follow me @ www.twitter.com/lancew)
my $rss_address = 'http://twitter.com/statuses/friends_timeline/73963.rss';

# A little print statement to tell me what the code is up to.
print "Getting original data set...\n";

# Grab the RSS from the internet and store it in anotherr scaler
my $rss_old = $ua1->request($req1)->as_string;



# Start a never ending While loop.
while (1) {
# Pause for a while (about 200 seconds) between cycles so there is time for your feeds to update
print "Pausing";
for ($count = 200; $count >= 1; $count--) {
print ".";
sleep(1);
}
# Now grab a new version of the RSS feed and store it in a scaler
print "\nGetting new dataset...\n";

my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(GET => $rss_address);
$req->authorization_basic('<user>', '<pass>');
my $rss_new = $ua->request($req)->as_string;


# I then split the scalers on the <ITEM> tag into arrays
@old = split /<item>/, $rss_old;
@new = split /<item>/, $rss_new;

# Then I run the two arrays through the ARRAY::DIFF modules
my $diff = Array::Diff->diff( \@old, \@new );

# Print out how many differences there are
print "\n".$diff->count."\n";

# Now set the old_rss scaler to equal the new one, so when we cycle next it has the RSS contents from now.
$rss_old = $rss_new;

# Look at the number of differences from ARRAY::DIFF and do some stuff if there is more than none
if ($diff->count > 0){

# Loop through an array of the differences addded (which I reverse to get the correct order)
foreach (reverse(@{$diff->added})) {
#Find the title of the twitter post, by regex'ing between the title tags
$_ =~ /<title>(.+)<\/title>/;

#then print it out to the console
print $1.".\n";

#Next we push it out to Snarl
# I use IPC::Open3 as per PBP, but you could use back ticks I guess
# So the cmd here creates a Snarl message that remains for 8 seconds with a title Twitter. $1 is what we found in the regex above
my $cmd = "\"C:\\Program Files\\Snarl_CMD_0.1\\Snarl_CMD.exe\" snShowMessage 8 \"Twitter\" \"$1\"";
my $pid = open3($wtr, $rdr, $err, $cmd);
my @response = <$rdr>;

#Then before we go onto the next new twitter post (tweet) wait for 1 second. This makes the growls appear/disapear one after another
sleep(1);
} # end of the foreach diff->added loop

} # end of the if $diff->count > 0 block


} # end of the while(1) loop


---------------
Links:
Perl is available all over the place, for Windows try Strawberry ( http://strawberryperl.com/ ) or Activestate ( http://www.activestate.com/Products/activeperl/ ).
Snarl is available for free from http://www.fullphat.net/
Snarl_cmd is available from http://tlhan-ghun.de/?q=node/59

[ view entry ] ( 3554 views ) permalink
Odeon "Fanatical about film, not so fussed about it's customers!" 

Tonight I went to watch the new Indiana Jones film, excellent acion flick!

Shame about the venue.

We went to the Odeon (leisureworld) in Southampton here in the UK. After getting our tichets and standing in the queues to get overpriced popcorn and drinks, we queued to hand over our tickets and the picture below shows what I was astounded and rather annoyed to see.





On the off chance it is not clear it is basically a big plasma/lcd screen right up high on the wall where everyone has to hand over their tickets.
What is on the screen, is the CCTV footage from cameras inside each theatre. You'll notice that if you happen to sit anywhere but near the back, anyone watching that big screen in the public auditorium part of the cinema can see you.

You are say there in a theatre you have paid (too much) for to watch a film, being shown to everyone who fancies watching. Thats a nice camera angle to see you eating your popcorn holding hands or cuddling your other half, picking your nose, scratching your groin... whatever.

It's not like you expect to be shown on a wide screen in public when you pay good money to watch a film is it. I could go into the silly FACT message saying you are going directly to hell if you take a photo or film the movie. (Like anyone who pays to see a movie in the UK is going to be pirating it! It;s been on the torrents from before it got to the UK for ages normally. Normally, it;s a illegal copy made by someone who works in the industry.. how many are normal members of the public, so why annoy me with the big warning message!

So I am paying a large amount of money (loads more than I could download it from the web for free) to be told if I even have a camera on me I might get taken away ina police car. Then I have to watch the entire film knowing that I am on camera my self... great!!

Fanatical about film!? When did your customer surveys tell you that people who are fanatical about going to the cinema (instead of watching a downloaded copy) really REALLY wanted to be on a wide screen TV in the auditorium.

Let me see, next time I want to catch a blockbuster, will I

A) Pay for over proced food and expensive seats at the cidema, where I shall be treated like a criminal and videod throughout.

or

B) Download it of the web (where it is normally available sooner than here anyway). Where I can eat popcorn at virtually no cost, sit on my comfy couch and not be surveilled let alone have my image projected on a wide screen ina bust auditorium!

No let me see... which one should i choose?

Thanks Odeon for reminding me that the Uk has way too much CCTV, and that people like you have completely forgotten you are in a service industry. You seem to have forgotten that you face stiff competition from TV, DVD, restaurants, bars, the internet and video games. Most of which don't treat melike a crook... well except for DVD which is your idiotic industry. And hey if I download it of the internet the FBI warnings are at least funny if it is an illegal copy.

So...

Probably shan't bother watsing my time at the Odeon (LeisureWorld) in Southampton again, shall check out some of the less intrusive cinemas next time I am foolish enough to want to watch a film at the cinema.

Perhaps I am over reacting, I am reading "Little Brother" by Cory Doctorow at the moment and maybe I am just a bit sensitive about my privacy and rights... maybe.

Goodnight.
[ view entry ] ( 2088 views ) permalink
Exhaustion is your friend. 

So this week I have been writing a literature review for my Bsc research project. Not been to bed before 2am all week, but in the end I was pretty happy with what I produced.

Fortunately, whilst I was in Bath back in April, I discovered an amazing piece of software called Zotero ( www.zotero.org ). Zotero to quote their site is:

Zotero [zoh-TAIR-oh] is a free, easy-to-use Firefox extension to help you collect, manage, and cite your research sources. It lives right where you do your work — in the web browser itself.


It has a plug-in to Neo Office (open office), which lets me add citations directly, it also builds the bibliography for me and maintains both the citations and the bibliography as you work.

As I worked on the literature review this week, I have been counting my blessings that I discovered this gem of a piece of software! It must have saved me quite seriously 6 or 7 hours work! Seriously! The last assignment I did without it (which was half the size I think) I spent 3 hours doing the referencing!!! So I am totally in love with Zotero!

Do check it out !
[ view entry ] ( 2376 views ) permalink
Creating a NoseRub widget in Widsets. 

Hi all,
I have been playing with NoseRub for a while and recently I reinstalled Widsets on my phone, so I thought I'd merge the two together and install a NoseRub Widget on my Widsets install.

NoseRub, is a decentralized social networking platform that I use primarily to aggregate my rss feeds from sites like Plazes, Twitter, del.icio.us, etc. It also aggregates my various feeds like the RSS feed for this blog, my Judo blog and podcast, etc.

Widsets is a widget platform by and for Nokia mobile phones, and other Symbian based phones. With very little effort you can turn pretty much any RSS feed into a widget. You can do this on the phone itself or as I'll demonstrate, through the www.widsets.com website.

I have created a couple of widgets in Widsets, using my NoseRub install to create the RSS feeds. I created one for my items and one for items from my "contacts". The scary thing was that within a day 70 odd people had used the widget. Meaning it was on 70 peoples mobile phones!

Anyway... below is a video showing how to do it and some text explaining it too. Let me know what you think.



First things first, you need a NoseRub installation and a Widsets account, with the client installed on your phone.

Next create a RSS feed in your NoseRub installation. You do this by going into the "Settings" tab and then Feeds. Then click create a feed and follow the prompts, choose if you want a feed of just your stuff or just your contacts, or of course you could grab both.

Once it is created you can copy the link location and use it in Widsets.

So... in Widsets.

Click into "My profile", then on "Create a new widget", give the widget a name and paste in that RSS feed from above. Click Next.

Now choose one of the default icons, or upload your own. Click next.
Click Finish and you are done.

Here is mine:
Add to my Widsets


Widgets in Widsets can be more interactive and I'll probably look at maybe building one that will update my NoseRub location. But I did say I'd try it in Python first. :-)


[ view entry ] ( 2060 views ) permalink
A quick catch up post. 

So, the blog has been quiet of late, mainly due to life interfering with bloggage. In fact that is not entirely true, I have blogging daily over at www.judocoach.com/blog where I for the 4th year am blogging my experience at the University of Bath.

This year I was not only a student, but a keynote lecturer.
Fancy huh!
So the slide deck turned out to be 48mb! So I turned it into a PDF (12MB) and finally I posted it up onto Slideshare.

To see all (okay most) of the videos, check my post over at http://www.judocoach.com/blog/index.php ... 326-043928

Anyway... so the upshot of all this is I am having to work hard to get assignments done for the course. Some videos to produce, a booklet, a literature review and a methodology. Phew!

It was interesting to put a slide deck together, and to present on technology to Judo coaches. It seems to have been received well and I hope it results in some positives.

I am back at work now and that is a strain after being off for two weeks, but I am mentally almost back there.

In technology news, Google released AppEngine to the world, world domination is definitely on their cards! It'll be interesting to see how it goes, Python in the cloud, the possibilities are intriguing. vendor lock-in will be an issue, consider reading James blog for more on vendor lock-in. There are a large number of Perl people trying to get Google to support Perl too, which might be cool seeing as I have been doing lots of Perl coding at the moment.

I am supposed to be doing some Python on my mobile too, but I have been busy, oh so busy. I have started writing a mobile client for www.noserub.com now that 0.6a has a location feature. I wonder what else would be useful...?

I should probably write more, but my PS3 calls!


[ view entry ] ( 1824 views ) permalink

<<First <Back | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | Next> Last>>