Saturday 2 April 2016

Some little t scripts to help with Twitter list management

In UER S03E02 I promised some scripts to help with Twitter list management, finally here they are. To use them you first need to install the application t which you can find here: https://github.com/sferik/t As t is a hard thing to search for, it is a good idea to keep this link handy - or a way to remember it. I usually search for sferik if I need to find it again. t requires Ruby - follow the instructions on that page to get it all set up & working for whatever platform you're on.

The scripts presented here run fine with sh or bash, but they are simple and could easily be adapted for DOS or wherever else you're using them. They're based mostly on the author's own examples - you can get more examples from t's page.

Please note I am certainly not a script guru and there may well be better ways to do these tasks. However they work (at least for me!). My naming convention contains the letters tw_ so that twitter scripts stay together; you can of course call them whatever you like.

1. tw_addtolist


#!/bin/sh
# usage: tw_addtolist user tolistname
t set active <yourusername>
t list add $1 $2
With all of these, the t set active command is only needed if you use more than one account with t. This simply adds one or many usernames to the specified list. Usage for multiple usernames - use quotes to keep the whole thing inside the one variable:

tw_addtolist 'user1 user2 user3' destinationlist

2. tw_listaddfromlist


#!/bin/sh
# usage: tw_listaddfromlist listtocopyfrom listtocopyto
t set active <yourusername>
t list member $1 | xargs t list add $2

This enables you to copy users from one list to another, including from someone else's list. So let's say you wanted your own copy of my situationroomlist called mysitroomlist, you could use:

tw_listaddfromlist feedmetv/situationroom mysitroomlist


3. tw_listcopy

The above example needs the list to be already created, do this with a t command or on the Twitter site itself. If you use t to create a list with an already existing name, it'll create a new one. A version of the above that'll create a list and copy to it is:

#!/bin/sh
# usage: tw_copylist fromlistname tolistname
t set active <yourusername>
t list create $2 'your list description'
t list member $1 | xargs t list add $2 

I use 'TW_LC' as the description to show myself that I used this script to create the list. You can use the description however you like or pass it from the command line with $3 etc.


4. tw_listfromfollowings

#!/bin/sh
# gets list of people user is following, adds them to list
# tw_listfromfollowings user tolistname
echo NOTE - MOST 50 RECENT TWEETERS ARE CHOSEN
t set active <yourusername>
t followings $1 -l --sort=tweeted |head -50 |grep -v 'RT @' | awk '{print $13}' | xargs t list add $2 
This script takes the followers of a user and adds it to your list. This of course works best for a person whose followings are tightly focused on a single subject. You may find problems adding a large number, so my example here takes the top 50 users in order of their last tweet and reminds you of this in annoying great big capital letters.

5. tw_unfollowtolist

This one gives you the ability to unfollow one or many accounts and add them to a list at the same time.

#!/bin/sh
# takes user(s) from $2 & adds them to list named in $1
# takes list of twitternames from $2
t set active <yourusername>
t unfollow $2
t list add $1 $2

usage for multiple users - use quotes to keep the whole thing inside the one variable:

tw_unfollowtolist destinationlist 'user1 user2 user3'
These are only the tip of the iceberg when it comes to some of the clever things that could be done with scripting knowledge or data processing. I for example use the power of t's csv output to enable me to import twitter data into SQL server or Excel for further use or analysis. If anyone would like a follow up to this post with some of that stuff explained, get in touch.


No comments:

Post a Comment