Created
November 17, 2019 12:35
-
-
Save redknight99/bd1f09d02a46acbfcf959c98eb4fad56 to your computer and use it in GitHub Desktop.
Revisions
-
redknight99 created this gist
Nov 17, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,66 @@ import json import oauth2 as oauth import requests import urllib CONSUMER_KEY = "CHANGEME" CONSUMER_SECRET = "CHANGEME" ACCESS_KEY = "CHANGEME" ACCESS_SECRET = "CHANGEME" def get_user_block_list(): consumer = oauth.Consumer(key=CONSUMER_KEY, secret=CONSUMER_SECRET) access_token = oauth.Token(key=ACCESS_KEY, secret=ACCESS_SECRET) client = oauth.Client(consumer, access_token) block_list_endpoint = "https://api.twitter.com/1.1/blocks/list.json" options = "?skip_status=true&include_entities=false&cursor=-1" block_list_endpoing = block_list_endpoing + options response, data = client.request(block_list_endpoint, method='GET') user_list = json.loads(data) blocked_users_list = [] for user in user_list["users"]: blocked_users_list.append(user["screen_name"]) if user_list["next_cursor"] != 0: more_accounts_to_get = True current_cursor = user_list["next_cursor"] while more_accounts_to_get == True: block_list_endpoint = "https://api.twitter.com/1.1/blocks/list.json" options = "?skip_status=true&include_entities=false&cursor=" + str(current_cursor) block_list_endpoint = block_list_endpoint + options response, data = client.request(block_list_endpoint, method='GET') user_list = json.loads(data) for user in user_list["users"]: blocked_users_list.append(user["screen_name"]) if user_list["next_cursor"] == 0: more_accounts_to_get = False else: current_cursor = user_list["next_cursor"] return blocked_users_list def unblock_user_list(blocked_user_list): consumer = oauth.Consumer(key=CONSUMER_KEY, secret=CONSUMER_SECRET) access_token = oauth.Token(key=ACCESS_KEY, secret=ACCESS_SECRET) client = oauth.Client(consumer, access_token) unblock_list_endpoint = "https://api.twitter.com/1.1/blocks/destroy.json" for screen_name in blocked_user_list: print("Now attempting to unblock: " + str(screen_name)) payload = {"screen_name": screen_name, "include_entities": False, "skip_status": True} response, data = client.request(unblock_list_endpoint, body=urllib.urlencode(payload), method='POST') return "Success!" if __name__ == '__main__': list_of_blocked_users = get_user_block_list() un_block_result = unblock_user_list(list_of_blocked_users)