Friday, February 6, 2009

How to post in both Twitter and Identica at once

Twitter + Identi.ca in one shot: twit.pl
I recently registered accounts on Twitter and Identi.ca. However, when I want to post a message on both, I have to manually copy and paste each message from a site to the other.
What I propose is to write a little Perl script to automate that process, so that each message that you write is automatically sent to both Twitter and Identi.ca.

I found the base for such a script on Dave Jacoby's blog. He actually did most of the work so there'll be very little change to make (Thanks Dave).
There are some CPAN modules to install (Net::Twitter from Chris Thompson and Modern::Perl from chromatic). That'll be a good example of using the cpan command line in Strawberry Perl.

Install Net::Twitter CPAN module on Strawberry Perl
This CPAN module is the keystone of Dave's script. It is a Perl interface to twitter.com.
To install the module in Strawberry Perl, follow those instructions:
  • Open a DOS shell (cmd.exe)
  • type cpan to open the cpan shell
  • type m Net::Twitter (beware, CPAN module names are case-sensitive) to get help about the module.
  • If it is not installed, you will get a message like this one:
cpan> m Net::Twitter
Fetching with LWP:
http://cpan.strawberryperl.com/authors/id/C/CT/CTHOM/CHECKSUMS
Module id = Net::Twitter
CPAN_USERID CTHOM (Chris Thompson )
CPAN_VERSION 2.06
CPAN_FILE C/CT/CTHOM/Net-Twitter-2.06.tar.gz
UPLOAD_DATE 2009-01-26
INST_FILE (not installed)

  • Type install Net::Twitter to start the install process.
  • If like me, you didn't have it installed, it will also try to add the JSON module dependency. This JSON format looks interesting by the way, please remind me to go check it back later.
  • Ignore all the warnings and chose default options when prompted.
  • If all goes well after the install is finished, you should get the following response to m Net::Twitter:
cpan> m Net::Twitter
Database was generated on Fri, 06 Feb 2009 21:31:03 GMT
Module id = Net::Twitter
CPAN_USERID CTHOM (Chris Thompson )
CPAN_VERSION 2.06
CPAN_FILE C/CT/CTHOM/Net-Twitter-2.06.tar.gz
UPLOAD_DATE 2009-01-26
MANPAGE Net::Twitter - Perl interface to twitter.com
INST_FILE C:\strawberry\perl\site\lib\Net\Twitter.pm
INST_VERSION 2.06

Run the same process for Modern::Perl (current version is 1.02).
I didn't get any problem installing those modules on my machine. Hope all goes smoothly for you also.
I noticed is that ActivePerl was still associated with .pl files (StrawberryPerl was installed after it). You'll need to change that association to c:\strawberry\perl\bin\perl.exe.

French expression of the day:
"une clef de voƻte": a keystone

Next posts:
  • twit.pl: using the Net::Twitter module
  • Improving on the Perl template
  • How to install and use Google Analytics on your Blogger blog
  • Perl help resources
  • POD

2 comments :

  1. Hi Dave,

    thanks for stopping by.
    I am new to the Perl community but it seems to me that it's ok if many people write the same little programs as long as it is built on top of a common module.
    You do not reinvent the wheel as all the functionalities are already available on CPAN. You just code what I would call the "applicative" part where you use the provided module functions that you need.
    Perl makes it almost as quick to write a short script as to find the equivalent script and learn how to use it. Plus you get the satisfaction of creating new code and understanding how it works so that you can improve on it easily.
    At least, that's the way I see it with my very little overview.

    ReplyDelete
  2. How does your Rebol tutorial teach me anything about Perl?!!
    Also, your example doesn't support Identi.ca so your statement is not even true ;p

    ReplyDelete