-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
50 lines (43 loc) · 1.57 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
from tweepy import Client, Paginator
from os import getenv
from dotenv import load_dotenv
load_dotenv()
api_key = getenv('API_KEY')
api_secret = getenv('API_SECRET')
access_token = getenv('ACCESS_TOKEN')
access_token_secret = getenv('ACCESS_TOKEN_SECRET')
my_user_id = getenv('MY_USER_ID')
tweet_id = getenv('TWEET_ID')
if None in [api_key, api_secret, access_token, access_token_secret, tweet_id]:
raise Exception('You have to provide all of the following env vars: API_KEY, API_SECRET, ACCESS_TOKEN, '
'ACCESS_TOKEN_SECRET, MY_USER_ID, and TWEET_ID.')
client = Client(
consumer_key=api_key,
consumer_secret=api_secret,
access_token=access_token,
access_token_secret=access_token_secret,
wait_on_rate_limit=True
)
followings = []
for response in Paginator(client.get_users_following, id=my_user_id, user_auth=True):
fetched_followings = response.data
if not fetched_followings:
print(f'in get_users_following, response: {response}')
continue
for following in fetched_followings:
followings.append(following.id)
i = 0
for response in Paginator(client.get_liking_users, tweet_id, user_auth=True):
users = response.data
if not users:
print(f'in get_liking_users, response: {response}')
continue
for user in users:
if user.id in followings:
print(f'{user.username} liked but not blocked')
continue
client.block(user.id)
i += 1
if i % 10 == 0:
print(f'blocked {i} accounts...')
print(f'Done.\nSuccessfully blocked {i} accounts.')