Stereonaut!

Archive for the ‘twitter’ Category

Sync your Twitter followers and friends

without comments

I have a couple of accounts in Twitter (namely @debian and @planetalinux) that are starting to bring a lot of followers (well, at least some of them). And given that I consider these accounts to be Twitter-polite enough, I like to follow the followers back too; however, this task sometimes gets really hard and it's tiring to go through the followers pages and follow those that I don't follow yet over and over.

So, I spent a few minutes and came up with this simple Ruby script that uses John Nunemaker's awesome Twitter gem.

#!/opt/local/bin/ruby

require "rubygems"
require "twitter"

httpauth = Twitter::HTTPAuth.new(
	ARGV[0] || 'yehyeh',
	ARGV[1] || 'kissm3'
)

base = Twitter::Base.new(httpauth)

i = 0
(base.follower_ids - base.friend_ids).each do |id|
  i += 1
  begin
    base.friendship_create id
  rescue Twitter::General => e
    puts "#{e.class}: #{e.message}"
  end
end
puts "#{i} new friendships."

i = 0
(base.friend_ids - base.follower_ids).each do |id|
  i += 1
  base.friendship_destroy id
end
puts "#{i} destroyed friendships."

puts "#{base.friend_ids.size} friends now."
puts "#{base.follower_ids.size} followers now."

What this little code does is exactly that, it will start following the followers you don't follow yet, and it will stop following the people that don't follow you back, right? Got it? It's basically synchronizing your friends with your followers. As said, this is particularly helpful when you are maintaining a community account and want to keep up befriending your kind followers :-) Handling the exception Twitter::General on line 18 is only done because the twitter gem raises it even when you are trying to befriend an account to which you have already requested friendship (like pending requests to protected updates accounts) or those of suspended accounts (spammers).

Written by David Moreno

June 10th, 2009 at 1:30 pm

Categorized in: debian, planeta linux, ruby, twitter

Tagged with , , , ,

Cheating the world you tweet less

with 6 comments

The number of updates on my Twitter page kind of bothers me sometimes. It's a reminder of the amount of time I've spent and wasted on Twitter, it's an ever-itching mole in front of my face. However, I can cheat the system and society and still feel good about myself. What if I just remove all freaking replies I've made, except for those of people I do care about (like my fiance or Ruby Boobie)? And also, I don't want to remove very recent replies.

Well, let's just do it already.

#!/opt/local/bin/perl

use Modern::Perl;

use Net::Twitter;
use DateTime::Format::DateParse;
use DateTime;

binmode STDOUT, ":utf8";

my $t = Net::Twitter->new(
    user => shift @ARGV || 'lazy_fuck',
    password => shift @ARGV || 'bl0wm3');

my $whitelist = [qw/maggit rubx axiombox/];

my $then = DateTime->now;
$then->subtract(days => 5);

my $x = 1;
for my $i (1..80) {

    my $tweets = $t->user_timeline({ page => $i, count => 200 })
        or die "No fish for you, loser.\n";

    for my $h (@$tweets) {
        next unless $h->{"in_reply_to_screen_name"};
        next if grep { $_ eq $h->{"in_reply_to_screen_name"} } @$whitelist;

        my $date = DateTime::Format::DateParse->parse_datetime($h->{"created_at"});
        next unless $date < $then;

        say $x, ": (", $h->{"id"}, ") ", $h->{"text"};
        $t->destroy_status($h->{"id"});
        $x++;
    }
}

This little fucker will try to fetch your latest 16'000 tweets (if you have… twat, *grin*, more than that, you've got real issues and I cannot help there, get a shrink or something).

It'll make 80 requests for your timeline (remember Twitter gives you a 100-request hour limit), so only if the reply doesn't come from a certain people AND the reply is older than a given period of time (I'm setting it to one week for me), it'll get rid of it. If a friend doesn't see the reply in a week, she probably never will. After that, it just destroys the tweet (or it tries at least, from my experience, Twitter is still experimenting a hell lot of issues on their service).

That way you can cheat the system removing useless tweets that no one (not even you or the recipient) cares about anymore. Or just… don't give a shit, and you are all set too.

The first time I ran it, I went from like 6k tweets to 2500, which was a nice drop :-) . If you feel like it, just grab it and customize to fit your needs. You will be needing the CPAN modules Modern::Perl, DateTimeDateTime::Format::DateParse and of course, Net::Twitter.

Written by David Moreno

June 8th, 2009 at 4:41 pm

Categorized in: perl, planeta linux, twitter

Tagged with , ,

@debianproject is now @debian!

with one comment

Thanks to Jamie, who used to have the name registered and now handed it over, Twitter Debian's Twitter username is now @debian (go follow Jamie now!). If you were already following @debianproject, nothing will change.

Having @debian on Twitter is actually kind of awesome!

Written by David Moreno

June 5th, 2009 at 11:08 am

Categorized in: debian, planet-debian, planeta linux, twitter

Tagged with , ,

Debian Maintainers now able to post to Debian Twitter

with 7 comments

I've added support for Debian Maintainers to post tweets to Debian Twitter (both on Identi.ca and Twitter). Feel free to use it.

Written by David Moreno

May 26th, 2009 at 3:17 pm

Twitter's OAuth + Perl

with one comment

During the last week, unbeatable Tatsuhiko Miyagawa uploaded Net::Twitter::OAuth to CPAN, which provides an awesome interface for Net::OAuth::Simple and Twitter by subclassing Net::Twitter. This way, it's very easy to develop Twitter client applications using its new OAuth method dropping the need for users to hand their credentials to third parties.

You will have to register your application on Twitter previously. You can do so here. If this is a web application that you will be building, you can provide a callback URL which is the page where the user will get redirected once she has granted access to your application. If you just want to test, setting a desktop application is probably the way to go.

Once you have registered your application, you will get two strings, key and secret consumer. Refer to general OAuth documentation for deeper details.

Install Net::Twitter::OAuth as any other Perl module:

$ sudo cpan Net::Twitter::OAuth

Now, using it is very simple:

my $client = Net::Twitter::OAuth->new(
  consumer_key    => "YOUR-CONSUMER-KEY",
  consumer_secret => "YOUR-CONSUMER-SECRET",
);

No transactions or requests have been made yet. Here you need the user's access and secret tokens. If you already have them, which means that the user has already gone through the authorization process, you have to pass it now (you already stored them on database, a configuration file or whatever the data model you use):

if ($access_token && $access_token_secret) {
  $client->oauth->access_token($access_token);
  $client->oauth->access_token_secret($access_token_secret);
}

Now you can query Twitter so it can provide you access:

unless ($client->oauth->authorized) {
  # The client is not yet authorized: Do it now
  print "Authorize this app at ", $client->oauth->get_authorization_url, " and hit RET\n";

  <STDIN>; # wait for input

  my($access_token, $access_token_secret) = $client->oauth->request_access_token;
  save_tokens($access_token, $access_token_secret); # if necessary
}

All these snippets come from the example's of Net::Twitter::OAuth. So basically, if you are not authorized, which means that either the user hasn't even been prompted for authorization or denied access before, then you get the authorization URL which you can give to the user to visit.

Once the user has granted access, you can call request_access_token which will return the user's tokens. Here's where you can save those tokens for future use.

After that block, you are pretty much done and can use the regular Net::Twitter methods:

my $res = $client->update({ status => 'me ownz oauth!!1' });

Soon, a real life application post using HTTP::Engine, KiokuDB and Net::Twitter::OAuth.

Written by David Moreno

May 21st, 2009 at 2:06 pm

Categorized in: http, perl, planeta linux, twitter

Tagged with , ,

On Twitter alerts and regular expressions

with 3 comments

I don't know if I'm the only one that does something like this, but I certainly trust I'm not alone.

I love regular expressions (to which some people say there's nothing regular about) and I just found TweetBeep recently, which is a simple alerts system. There's nothing really new or innovative about it, given that you can get the results yourself using advanced search on Twitter and consuming the results from a feed. However, I for sure, I don't want to spend time setting any of that up, and they do that quite easily, which is the whole difference, ease of use. You can get the results on time intervals via mail. Rocks.

So, one of my alerts is about regular expressions: I'm receiving everything Twitter tweets about them, whether regex, regexp, regexes, regexps, etc. are mentioned, I get them. Now, I feel a bit nerdish/dorky about it given that I like to reply on those tweets on totally random people and try help them whenever it's possible (or just learn a bit more from other regex gurus), but what the hell.

Now, the good thing about this is that being a "good person" and fellow regex buddy with people is starting to pay off. Whether I'm getting new very interesting followers, I also found a nice opportunities niche to take advantage of, and a couple of gigs have come up. I worship building strong relationships with people (as in long-term clients), and when starting to get to know some persons via a common interesting thing such as a regular expressions is just awesome, little piece of awesomeness.

For the geeky part of this post, if my regular expression Twitter alert had to be written as a regex, this would be it:

/regex(?:(ps?|es))?/

The questions now is, should I start following /regular\s*expres{1,2}ions?/ too? Maybe I will :-)

Written by David Moreno

April 12th, 2009 at 7:17 am

Categorized in: nerd, planeta linux, regex, twitter

Tagged with , , ,

Rubx: Twitter's Ruby shell

with 4 comments

rubxRubx, also known as Ruby Boobie, is a nice spoiled girlie bot that runs on Twitter. She listens when you talk to her and when you do, it'll better be with Ruby: She will interpret your tweet in Ruby and reply to you with what your code returns.

How does it work? You send a message to her:

@rubx "The day I was born it was a " << Time.local(1984, "aug", 8).strftime("%A")

And @rubx will reply:

@damog "The day I was born it was a Wednesday"

Go see more about her (examples, FAQ, etc) on axiombox.com/rubx or on her Twitter profile.

As we tested the hack, a bunch of people started interacting with Rubx too, some people calling her Twitter Line Interface Ruby Interpreter! :) . See what other people has tried with her here.

Written by David Moreno

April 6th, 2009 at 9:32 am

Debian on Twitter

with 6 comments

Or… for those who care about Twitter and Debian :)

We've setup a Twitter account for the project to use on Twitter. Go follow it, go now!

twitter.com/debianproject

Now, the interesting part about this is that any Debian developer with a GPG key on the Debian keyring can tweet to it. You basically only have to do something like this:

$ echo "Squeeze is scheduled for Winter 2014" | gpg --clearsign | lwp-request -m POST http://twitter.debian.net/post

…or, what it's the same, just send a clearsigned POST data to http://twitter.debian.net/post. If the data is signed by a Debian developer, it'll go through and post it. The Debian uid is appended on the tweet, as found on Debian's LDAP DB, so if joetheplumber@d.o is the one posting, it'll be posted with "(via joetheplumber)" on it.

If you are more interested about this, you can go to twitter.debian.net where you will find deeper information and details about this service.

I encourage you, Debian user and advocate, to start following the @debianproject account; and I encourage you, Debian developer, to communicate with our users and advocates by using and posting to this service.

More news to follow soon.

UPDATE: Support for Identi.ca has been added and now both Twitter and Identi.ca accounts are updated at once and sync'ed.

Written by David Moreno

March 22nd, 2009 at 9:33 am

Categorized in: debian, gpg, planet-debian, planeta linux, twitter

Tagged with , ,

Get Adobe Flash playerPlugin by wpburn.com wordpress themes