2023-03-31 19:20:58 +02:00
|
|
|
from app.libraries.database import Database
|
|
|
|
from app.libraries.setup import Setup
|
|
|
|
from mastodon import Mastodon
|
|
|
|
import pdb
|
|
|
|
|
|
|
|
def followers_list(my_id):
|
|
|
|
|
|
|
|
followers_list = []
|
|
|
|
|
|
|
|
temp_followers_list = {}
|
|
|
|
|
|
|
|
i = 0
|
|
|
|
|
|
|
|
while True:
|
|
|
|
|
|
|
|
if i == 0:
|
|
|
|
|
|
|
|
temp_followers_list[i] = mastodon.account_followers(my_id, limit=80)
|
|
|
|
|
|
|
|
if temp_followers_list[i] == []:
|
|
|
|
|
|
|
|
return followers_list
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
temp_followers_list[i] = mastodon.fetch_next(temp_followers_list[i-1]._pagination_next)
|
|
|
|
|
|
|
|
dict_len = len(temp_followers_list[i])
|
|
|
|
|
|
|
|
ii = 0
|
|
|
|
|
|
|
|
while ii < dict_len:
|
|
|
|
|
|
|
|
followers_list.append(temp_followers_list[i][ii])
|
|
|
|
|
|
|
|
ii += 1
|
|
|
|
|
|
|
|
if len(temp_followers_list[i]) < 80:
|
|
|
|
|
|
|
|
return followers_list
|
|
|
|
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|
|
|
db = Database()
|
|
|
|
|
|
|
|
setup = Setup()
|
|
|
|
|
|
|
|
mastodon = Mastodon(
|
|
|
|
access_token = setup.mastodon_app_token,
|
|
|
|
api_base_url= setup.mastodon_hostname
|
|
|
|
)
|
|
|
|
|
|
|
|
my_id = mastodon.me()
|
|
|
|
|
|
|
|
followers = followers_list(my_id)
|
|
|
|
|
2023-04-02 10:28:30 +02:00
|
|
|
db.reset()
|
|
|
|
|
2023-03-31 19:20:58 +02:00
|
|
|
for follower in followers:
|
|
|
|
|
2023-04-01 10:34:53 +02:00
|
|
|
db.find_follower(follower.acct)
|
2023-03-31 19:20:58 +02:00
|
|
|
|
|
|
|
last_local, last_remote = db.last_total()
|
|
|
|
|
|
|
|
local_followers, remote_followers = db.totals()
|
|
|
|
|
|
|
|
if last_local != 0:
|
|
|
|
|
|
|
|
local_incr = local_followers - last_local
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
local_incr = local_followers
|
|
|
|
|
|
|
|
if last_remote != 0:
|
|
|
|
|
|
|
|
remote_incr = remote_followers - last_remote
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
remote_incr = remote_followers
|
|
|
|
|
|
|
|
db.save_total(local_followers, local_incr, remote_followers, remote_incr)
|
|
|
|
|
2023-04-02 10:28:30 +02:00
|
|
|
unfollowers = db.find_unfollowers()
|
|
|
|
|
2023-03-31 19:20:58 +02:00
|
|
|
post_text = f"@{mastodon.me().acct}\nseguidors: {len(followers)}\n"
|
|
|
|
|
2023-05-02 20:22:33 +02:00
|
|
|
post_text += f"locals: {local_followers} ({local_incr})\nremots: {remote_followers} ({remote_incr})\n"
|
2023-03-31 19:20:58 +02:00
|
|
|
|
2023-05-03 18:11:31 +02:00
|
|
|
if unfollowers != []:
|
2023-04-02 10:28:30 +02:00
|
|
|
|
2023-05-02 20:22:33 +02:00
|
|
|
post_text += f'\nJa no et segueix:\n'
|
|
|
|
|
2023-04-02 10:28:30 +02:00
|
|
|
for unfollow in unfollowers:
|
|
|
|
|
2023-05-02 20:22:33 +02:00
|
|
|
post_text += f'- {unfollow}'
|
|
|
|
|
|
|
|
unfollow_id = mastodon.account_lookup(unfollow).id
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
mastodon.account_unfollow(unfollow_id)
|
|
|
|
|
|
|
|
post_text += f' (has deixat de seguir-lo)\n'
|
|
|
|
|
|
|
|
except:
|
|
|
|
|
|
|
|
post_text += f' (ja no existeix)\n'
|
|
|
|
|
|
|
|
pass
|
2023-04-02 10:28:30 +02:00
|
|
|
|
2023-03-31 19:20:58 +02:00
|
|
|
mastodon.status_post(post_text, in_reply_to_id=None, visibility='direct')
|
|
|
|
|
|
|
|
|