from mastodon import Mastodon from pprint import pprint import os import time import datetime from pprint import pprint today = datetime.date.today() text_file = open("answers_results.txt", "a+") text_file.write("Data collected on : "+str(today)+"\n"+"\n") #toots id and instances position refer to same post #FOR EXAMPLE #toot_id[0] goes with instances[0] # IMPORTANT: Ensure the order of elements in toot_id and instances # Are the same as the order of the tokens tokens.txt toot_id = [101767654564328802, 101767613341391125] instances = ["https://todon.nl/", "https://meow.social/"] #toots token order is also the same #FOR EXAMPLE #toot_id[0] goes with instances[0] and now goes with line nr1 from txt file with open('token.txt', 'r') as token: for n, token_line in enumerate(token.readlines()): base_url = instances[n] print(token_line, base_url) # token_line é uma das linhas de token.txt # como a les em token.readlines() n precisas de ler outra ver # e podes usar apenas a var token_line mastodon = Mastodon(access_token=token_line.replace('\n', ''), api_base_url=(str(base_url))) toot_id_current = toot_id[n] print(toot_id_current) status = mastodon.status_context(id=(toot_id_current)) descendants = mastodon.status_context(id=(toot_id_current))["descendants"] print(toot_id_current) for answer in descendants: pprint(answer["id"]) # geral = mastodon.status(answer["id"])) avatar = mastodon.status(answer["id"])['account']['avatar'] name = mastodon.status(answer["id"])['account']['display_name'] bot = mastodon.status(answer["id"])['account']['bot'] content = mastodon.status(answer["id"])['content'] pprint("Avatar:" + "\n" + str(avatar) + "\n" + "\n") pprint("Name:" + "\n" + str(name) + "\n" + "\n") pprint("Bot:" + "\n" + str(bot) + "\n" + "\n") pprint("Content:" + "\n" + str(content) + "\n" + "\n") text_file.write("Avatar:" + "\n" + str(avatar) + "\n" + "\n") text_file.write("Name:" + "\n" + str(name) + "\n" + "\n") text_file.write("Bot:" + "\n" + str(bot) + "\n" + "\n") text_file.write("Content:" + "\n" + str(content) + "\n" + "\n" + "\n") time.sleep(2)