-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfollowback.py
65 lines (54 loc) · 1.91 KB
/
followback.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
from mastodon import Mastodon
mode = "addtolist"
# mode = "unfollow"
instance = 'https://mastodon.nl'
masto = Mastodon(
access_token = os.environ['MASTO_TOKEN'],
api_base_url = instance
)
donotunfollowListID = 1048
doesnotfollowmeListID = 1097
followtreshold = 25
followsme=[]
ifollow=[]
donotunfollow = []
doesnotfollowme = []
followers = masto.account_followers(masto.me()['id'])
allfollowers=masto.fetch_remaining(followers)
for i in allfollowers:
followsme.append(i['id'])
following = masto.account_following(masto.me()['id'])
allfollowing=masto.fetch_remaining(following)
for i in allfollowing:
ifollow.append(i['id'])
tofollow=[x for x in followsme if x not in ifollow]
for user in allfollowers:
if user['statuses_count'] > followtreshold and "missing.png" not in user['avatar'] and user['id'] in tofollow:
try:
result=masto.account_follow(user['id'])
print("Followed ", user['username'])
except:
# print("Could not follow ", user['username'])
pass
for i in masto.list_accounts(donotunfollowListID):
donotunfollow.append(i['id'])
for i in masto.list_accounts(doesnotfollowmeListID):
masto.list_accounts_delete(doesnotfollowmeListID, i['id'])
tounfollow=[x for x in ifollow if x not in followsme]
for user in allfollowing:
if user['id'] not in donotunfollow and user['id'] in tounfollow:
try:
if mode == "addtolist":
masto.list_accounts_add(doesnotfollowmeListID, user['id'])
# print("User ", user['username'], " added to list")
elif mode == "unfollow":
masto.account_unfollow(user['id'])
print("Unfollowed user ", user['username'], ".")
for user in allfollowers:
if user['statuses_count'] < followtreshold and "missing.png" in user['avatar']:
masto.account_unfollow(user['id'])
print(user['username'])
except:
# print("User ", user['username'], " could not be processed")
pass