(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version



Destroying Twitter Friendships with twitterdeaf.pl




2009/01/21

As I said this morning at Twitter Deaf, I decided to unfollow people who follow too many other people. No offense, but if you follow a lot of people, you are effectively deaf to Twitter messages, so why should I follow you? You can't "hear" me and if I'm following hundreds of people who follow me, I can't "hear" you, either. I started deleting people by hand but quickly realized that was silly: Twitter has a simple API.

So I wrote a little Perl script to hunt the people with too many friends. I decided to start the cut at 300 - under that, you are safe for this first pass. I may be more draconian later and I may add more criteria; for example I may unfollow if you are a daily chatterbox. Again, no offense but chatty people can make it hard to hear other people.

Some things to explain about the code: I pulled info from the Twitter API page. I wrote it in simple Perl, no hard to find modules.

I've always thought LWP's "get" was odd for returning a string rather than an array of lines, but that's what it does, so it has to be split into an array.

Twitter limits how many calls you can make per hour so watch out for that if you have a lot of people.

You need to be logged in to Twitter before you run this. You can do authentication with LWP, but why bother?

I didn't put in error checking for failure to be logged in or for exceeding the call limit. You can do that with the regular LWP also if you want to go to the trouble, but this is a one-off, so why bother yet again?

I decided NOT to call the API to "destroy" the friendship and simply used this to get a list of the people and their counts. If you need to get beyond page 1 (100 friends), you need to set $x to the next page and so on. Of course you can put this in a loop but remember the 200 status call limit.. you'll need to be waiting around anyway. What this saves you is having to click on each person before you decide their fate.

There's no reason not to just keep on in one big loop either but that's not what I was thinking when I wrote it, so it accumulates names first. Don't like it, change it - but why bother?

I got my list and then went back into Twitter and deleted each person manually. Note there is plenty of other information in the status returned; you may want to print out more of it (like Updates, which is "statuses_count" in the "show" results - dumb, dumb API!) to help you decide.

If you really want to call "destroy" automatically, go ahead - that's your business, not mine.

After doing this, I'm down to 46 people. If I need to cut it more, I will, but it feels pretty good. I feel like I can hear again - I'm not Twitter Deaf..

#!/usr/bin/perl
use LWP::Simple;
use URI::URL;
my $count=0;
my $max=300;

 my $url= url('http://twitter.com/statuses/friends/pcunix.xml');
 $url->query_form(page=>$x);
 my $response=get($url);
 my @responses=split /\n/,$response; 
 foreach (@responses) {
   if (/<screen_name>/) {
     push @ids,$_;
     $count++;
  }
}
foreach (@ids) {
  s/<screen_name>//;
  s/<.screen_name>/.xml/;
  $id=$_;
  $count++;
  if ($count > 199)  {
     print "Pausing 60 minutes..\n";
     $count=0;
     sleep 3600;
   }
  my $show=get("http://twitter.com/users/show/$_");
  my @show= split /\n/,$show;
  foreach (@show) {
    if (/<friends_count>/) {
      s/<friends_count>//;
      s/<.friends_count>//;
      if ($_ > $max) {
           print "($count) $id $_\n";
           #$id=~ s/.xml//;
           #get("http://twitter.com/friendships/destroy/$id");
      } # large number
    } # if count
   } # foreach @show
 } # foreach @ids




Click here to add your comments





Thu Jan 22 00:18:02 2009: Subject:   BenTheMeek

gravatar
perl <3. :) just a question because I am too lazy to look it up: If you unfollow someone that is still following you, will you still receive their comments on tweets you make when they @pcunix? That would make sense, but I just wanted to make sure.





Thu Jan 22 00:44:50 2009: Subject:   TonyLawrence

gravatar
Yes.. you can @reply anyone.

You can't send a direct message unless the person is following you. You can @reply (unless they have blocked you).

However: If you @reply to someone who does NOT follow you, they won't see it in their main display; it only goes the the "@reply" section.

Clear? See http://blog.twitter.com/2008/05/how-replies-work-on-twitter-and-how.html for even more details :-)



Thu Jan 22 10:50:51 2009: Subject:   NickBarron

gravatar
Well some good morning reading for me, thanks Tony :)



Thu Jan 22 13:47:22 2009: Subject:   TonyLawrence

gravatar
It was so nice this morning to check twitter and be able to catch up in two minutes or less.

Twitter Deaf no more!

A few "Qwitter" messages in my email (automatic service that unfollows when someone unfollows you). Yeah, like those people mattered anyway..





Mon Feb 2 04:44:46 2009: Subject:   MartinMalden
http://www.wealthydragon.com/blog/
gravatar
Tony, hi,

In order to cut down on the background noise, I just installed TweetDeck this weekend and so far I'm quite impressed.

It has enabled me to establish groups to which I can allocate people I'm following. So for example I have a group called IM gurus to which I've added 2 or 3 people. Another for real friends (as opposed to virtual friends), and so on.

These groups are displaid in separate panes and I've also set up a pane for replies and a pane for DMs.

As a result I'm now seeing the tweets for only about a dozen or so people, all neatly displaid in separate panes.

It also retains my search criteria, which I find extremely useful. It means that every time I fire up TweetDeck it immediately resumes searching based on the criteria I had established when I was last using it.

Because it's a third party app it's subject to the 100 api calls per hour limit, but by changing the settings to request updates every 2 minutes instead of every minute that immediately ceased to be a problem.

It's turned Twitter into a really powerful tool for me by cutting out all the clutter and enabling me to organise the information flow in a way that's useful and relevant to me.

Cheers,

Martin.



Mon Feb 2 12:04:45 2009: Subject:   TonyLawrence

gravatar
Thanks, I had tried TweetDeck but I'm happier this way.

Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar



numly esn 95056-090121-867699-65
numly barcode

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.

book graphic Internet Income guide

My Hard Truths about Easy Money on the Internet will show you how to make money on the Internet!

 I sell and support
 Kerio Mail server




pavatar.jpg
More:
       - Blogging
       - Programming
       - Perl
       - Web/HTML


Unix/Linux Consultants

Skills Tests

Guest Post Here








card_image






My Favorites

Change Congress