Skip to content

Instantly share code, notes, and snippets.

@invisiblefunnel
Created January 17, 2021 03:56
Show Gist options
  • Save invisiblefunnel/f4b357c44fc87685eda9ce6330cd8486 to your computer and use it in GitHub Desktop.
Save invisiblefunnel/f4b357c44fc87685eda9ce6330cd8486 to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "manual-recruitment",
"metadata": {},
"outputs": [],
"source": [
"import os\n",
"import sys\n",
"from time import sleep as chillout\n",
"\n",
"import requests\n",
"from tqdm.notebook import tqdm\n",
"import twitter"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "hundred-header",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Keeping 61 preferred friends unmuted\n"
]
}
],
"source": [
"preferred_friends = [\n",
" # redacted\n",
"]\n",
"\n",
"print(\"Keeping\", len(preferred_friends), \"preferred friends unmuted\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "fatal-bronze",
"metadata": {},
"outputs": [],
"source": [
"client = twitter.Api(\n",
" consumer_key=os.environ[\"CONSUMER_KEY\"],\n",
" consumer_secret=os.environ[\"CONSUMER_SECRET\"],\n",
" access_token_key=os.environ[\"ACCESS_TOKEN_KEY\"],\n",
" access_token_secret=os.environ[\"ACCESS_TOKEN_SECRET\"]\n",
")\n",
"\n",
"def GetMuted():\n",
" cursor = -1\n",
" while True:\n",
" next_cursor, previous_cursor, users = client.GetMutesPaged(cursor=cursor)\n",
" yield from users\n",
" if next_cursor == 0 or next_cursor == previous_cursor:\n",
" break\n",
" else:\n",
" cursor = next_cursor\n",
" chillout(45)\n",
"\n",
"def GetFriends():\n",
" cursor = -1\n",
" while True:\n",
" next_cursor, previous_cursor, users = client.GetFriendsPaged(cursor=cursor)\n",
" yield from users\n",
" if next_cursor == 0 or next_cursor == previous_cursor:\n",
" break\n",
" else:\n",
" cursor = next_cursor\n",
" chillout(20)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "latin-vaccine",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "30d49f41173e4809874454760b34e366",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Fetching list of friends: 0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "8c5f69248e6f4c0b8e2d6b59588b9cb4",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Fetching list of muted users: 0it [00:00, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"friends = [u.screen_name for u in tqdm(GetFriends(), desc=\"Fetching list of friends\")]\n",
"muted = [u.screen_name for u in tqdm(GetMuted(), desc=\"Fetching list of muted users\")]"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "current-holocaust",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "d894eab975a54b2382b23921ef8c72c8",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Unmuting 1 preferred friends: 0%| | 0/1 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"to_unmute = set(friends) & set(preferred_friends) & set(muted)\n",
"\n",
"for screen_name in tqdm(to_unmute, desc=f\"Unmuting {len(to_unmute)} preferred friends\"):\n",
" client.DestroyMute(screen_name=screen_name)\n",
" chillout(10)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "attempted-warehouse",
"metadata": {},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "6f185d713db4413ab43333658487e0c4",
"version_major": 2,
"version_minor": 0
},
"text/plain": [
"Muting 6 friends: 0%| | 0/6 [00:00<?, ?it/s]"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"to_mute = set(friends) - set(preferred_friends) - set(muted)\n",
"\n",
"for screen_name in tqdm(to_mute, desc=f\"Muting {len(to_mute)} friends\"):\n",
" client.CreateMute(screen_name=screen_name)\n",
" chillout(10)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment