APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Destroying Twitter Friendships with twitterdeaf.pl

© January 2009 Anthony Lawrence

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..

use LWP::Simple;
use URI::URL;
my $count=0;
my $max=300;

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

Got something to add? Send me email.

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> Destroying Twitter Friendships with twitterdeaf.pl


Inexpensive and informative Apple related e-books:

Take Control of iCloud

iOS 10: A Take Control Crash Course

Take Control of Pages

Sierra: A Take Control Crash Course

Take Control of iCloud, Fifth Edition

More Articles by © Anthony Lawrence

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

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: 5226   TonyLawrence

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 (link) for even more details :-)

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

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

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

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: 5277   MartinMalden

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.



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

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


Printer Friendly Version

Have you tried Searching this site?

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.

Contact us

Printer Friendly Version

I had a life once. Now I have a computer. (unknown)

Linux posts

Troubleshooting posts

This post tagged:





Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode