Last active
June 8, 2018 08:56
-
-
Save pmakholm/ea23a5a1bb8f13ac5cacb2470db9474d to your computer and use it in GitHub Desktop.
Script to maintain a twitter list of tweeps following me with no follow back.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# Rough script to maintain a twitter list with tweeps following me without | |
# being followed back | |
# | |
# Requirements: | |
# - Install twurl from https://github.com/twitter/twurl | |
# - Follow the 'Getting started' section of the README for twurl | |
# - Set your twitter username and list name below | |
# | |
# NOTICE: "Rough" implies that error handling and over all user experience might | |
# be lacking. | |
# | |
# Copyright (c) 2018 Peter Makholm <peter@makholm.net> | |
# This work is licensed under a Creative Commons Attribution 4.0 International License. | |
# https://creativecommons.org/licenses/by/4.0/ | |
use strict; | |
use JSON; | |
# Set you Twitter username and the list name here: | |
my $username = 'pmakholm'; | |
my $listname = 'my-followers'; | |
sub get_friends { | |
my @friends; | |
my $cursor = "-1"; | |
while( $cursor ne "0" ) { | |
my $data = decode_json qx(twurl '/1.1/friends/list.json?include_user_entities=false&skip_status=true&count=200&cursor=$cursor'); | |
die $data->{errors}->[0]->{message} if $data->{errors}; | |
for (map { $_->{screen_name} } @{ $data->{users} || [] }) { | |
push @friends, $_; | |
} | |
$cursor = $data->{next_cursor_str}; | |
} | |
return @friends; | |
} | |
sub get_followers { | |
my @followers; | |
my $cursor = "-1"; | |
while( $cursor ne "0" ) { | |
my $data = decode_json qx(twurl '/1.1/followers/list.json?include_user_entities=false&skip_status=true&count=200&cursor=$cursor'); | |
die $data->{errors}->[0]->{message} if $data->{errors}; | |
for (map { $_->{screen_name} } @{ $data->{users} || [] }) { | |
push @followers, $_; | |
} | |
$cursor = $data->{next_cursor_str}; | |
} | |
return @followers; | |
} | |
sub get_list_members { | |
my @members; | |
my $cursor = "-1"; | |
while( $cursor ne "0" ) { | |
my $data = decode_json qx(twurl '/1.1/lists/members.json?slug=$listname&owner_screen_name=$username&count=2000&cursor=$cursor'); | |
die $data->{errors}->[0]->{message} if $data->{errors}; | |
for (map { $_->{screen_name} } @{ $data->{users} || [] }) { | |
push @members, $_; | |
} | |
$cursor = $data->{next_cursor_str}; | |
} | |
return @members; | |
} | |
sub add_list_members { | |
print "Adding @{[ scalar @_ ]} list members\n"; | |
while (my @add = splice @_, 0, 100) { | |
my $data = decode_json qx(twurl -d 'slug=$listname&owner_screen_name=$username&screen_name=@{[join",",@add]}' /1.1/lists/members/create_all.json); | |
die $data->{errors}->[0]->{message} if $data->{errors}; | |
} | |
} | |
sub del_list_members { | |
print "Removing @{[ scalar @_ ]} list members\n"; | |
while (my @add = splice @_, 0, 100) { | |
my $data = decode_json qx(twurl -d 'slug=$listname&owner_screen_name=$username&screen_name=@{[join",",@add]}' /1.1/lists/members/destroy_all.json); | |
die $data->{errors}->[0]->{message} if $data->{errors}; | |
} | |
} | |
my %friends; | |
$friends{$_} = 1 for get_friends; | |
my %followers; | |
$followers{$_} = 1 for get_followers; | |
my %members; | |
$members{$_} = 1 for get_list_members; | |
add_list_members( grep { !$members{$_} and !$friends{$_} } keys %followers ); | |
del_list_members( grep { $friends{$_} or !$followers{$_} } keys %members ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment