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) db.reset() for follower in followers: db.find_follower(follower.acct) 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) unfollowers = db.find_unfollowers() post_text = f"@{mastodon.me().acct}\nseguidors: {len(followers)}\n" post_text += f"locals: {local_followers} ({local_incr})\nremots: {remote_followers} ({remote_incr})" if unfollowers != None: for unfollow in unfollowers: post_text += f'\nJa no et segueix:\n@{unfollow}' mastodon.status_post(post_text, in_reply_to_id=None, visibility='direct')