Created
August 19, 2018 07:40
-
-
Save momota10/abb4b4b25380cb2c831a8cc302d64a4e to your computer and use it in GitHub Desktop.
Script to adjust who is following on twitter. Just unfollow users without description (simple)
This file contains hidden or 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
import json | |
from time import sleep | |
from requests_oauthlib import OAuth1Session | |
CK = "" | |
CS = "" | |
AT = "" | |
ATS = "" | |
twitter = OAuth1Session(CK, CS, AT, ATS) | |
cursor = '' | |
while True: | |
url = "https://api.twitter.com/1.1/friends/list.json" | |
if cursor == '': | |
params ={'screen_name' : 'monopatch7', 'count': 200, 'skip_status': True, 'entities': False} | |
else: | |
params ={'screen_name' : 'monopatch7', 'count': 200, 'skip_status': True, 'entities': False, 'cursor': cursor} | |
res = twitter.get(url, params = params) | |
res_dict = json.loads(res.text) | |
cursor = res_dict['next_cursor_str'] | |
print(cursor) | |
if cursor == '': | |
break | |
for row in res_dict['users']: | |
sleep(1) # Measures to limit API | |
if row['description'] == '': | |
screen_name = row['screen_name'] | |
print('screen_name is ', screen_name) | |
unfollow_url = 'https://api.twitter.com/1.1/friendships/destroy.json' | |
params = {'screen_name': screen_name} | |
unfollow_res = twitter.post(unfollow_url, params = params) | |
print(unfollow_res) | |
sleep(10) # Measures to limit API | |
print('finish') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment