You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
3.6 KiB
Python

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, 101767845648108564, 101767859212894722, 101767871935737959, 101767878557811327, 101772545369017811, 101767981291624379, 101767995246055609, 101772553091703710, 101768372248628715, 101768407716536393, 101768414826737939, 101768421746838431, 101771801100381784, 101771425484725792, 101771434017039442, 101771437693805317, 101782008831021451, 101795233034162198]
instances = ["https://todon.nl/", "https://meow.social/", "https://queer.party/", "https://scholar.social/", "https://eletusk.club/", "https://abdl.link/", "https://mastodon.starrevolution.org/", "https://mastodon.technology/", "https://quey.org/", "https://bsd.network/", "https://freeradical.zone/", "https://linuxrocks.online/", "https://mastodont.cat/", "https://qoto.org/", "https://mastodon.host/", "https://mastodon.gamedev.place/", "https://hotwife.social/", "https://hostux.social/", "https://mastodon.social/", "https://post.lurk.org/"]
#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]
description = mastodon.instance()['description']
#print instance name and description
pprint("Instance:" + "\n" + str(base_url) + "\n" + "\n")
pprint("Description:" + "\n" + str(description) + "\n" + "\n")
text_file.write("<h3 class='instance'>" + str(base_url) + "</h3>" + "\n" + "\n")
text_file.write("<h4 class='description'>" + str(description) + "</h4>" + "\n" + "\n")
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']
toot = mastodon.status(answer["id"])['content']
text_file.write("<img src='"+ str(avatar) + "' />" + "\n" + "\n")
text_file.write("<h3 class='name'>" + str(name) + "</h3>" + "\n" + "\n")
text_file.write("<h4 class='bot'>" + "Bot: " + str(bot) + "</h4>" + "\n" + "\n")
text_file.write("<p class='answer'>" + "\n" + str(toot) + "</hp>" + "\n" + "\n")
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(toot) + "\n" + "\n" + "\n")
time.sleep(2)