Added masto-mutuals.py
parent
405cc9af81
commit
7dbe0f86a5
@ -0,0 +1,46 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
from mastodon import Mastodon
|
||||
|
||||
mastodon = Mastodon(
|
||||
access_token = 'apptoken.secret', #app authtoken
|
||||
api_base_url = 'https://lgbt.io'
|
||||
)
|
||||
|
||||
user_id = mastodon.me()['id']
|
||||
|
||||
def fetch_user_ids(func, idval=user_id):
|
||||
user_ids = []
|
||||
initial = True
|
||||
while True:
|
||||
users = func(idval) if initial else mastodon.fetch_next(users)
|
||||
initial = False
|
||||
if users is None or len(users)==0:
|
||||
break
|
||||
for user in users:
|
||||
user_ids.append(user['id'])
|
||||
return user_ids
|
||||
|
||||
followed_ids = fetch_user_ids(mastodon.account_following)
|
||||
follower_ids = fetch_user_ids(mastodon.account_followers)
|
||||
mutual_ids = [i for i in followed_ids if i in followed_ids and i in follower_ids]
|
||||
|
||||
list_id = None
|
||||
for l in mastodon.lists():
|
||||
if l['title'] == 'mutuals':
|
||||
list_id = l['id']
|
||||
if list_id is not None:
|
||||
break
|
||||
if list_id is None:
|
||||
l = mastodon.list_create('mutuals')
|
||||
list_id = l['id']
|
||||
|
||||
list_ids = fetch_user_ids(mastodon.list_accounts, idval=list_id)
|
||||
toadd_ids = [i for i in mutual_ids if i not in list_ids]
|
||||
torm_ids = [i for i in list_ids if i not in mutual_ids]
|
||||
|
||||
if len(toadd_ids) > 0:
|
||||
mastodon.list_accounts_add(list_id, toadd_ids)
|
||||
|
||||
if len(torm_ids) > 0:
|
||||
mastodon.list_accounts_delete(list_id, torm_ids)
|
||||
Loading…
Reference in New Issue