Hydrating posts from Mastodon

ADOReD is harvesting Mastodon social media posts, and the social media post IDs can be downloaded from either the API or the Dashboard (for instance by executing text search queries).

Once a text search is executed, some Mastodon post IDs can be downloaded in CSV format, for instance:

TweetId
universeodon.com/@popsci/109664109504102472
mendeddrum.org/@Troggie/109665268880199351
mstdn.social/@TimInHonolulu/109665744876967965
mas.to/@nberlat/109666008731810004
mastodon.online/@phillfarrugia/109666136628267939
mastodon.world/@Dottiedot1/109666255063068262
fediscience.org/@salonium/109667210285416891
urbanists.social/@foxyjewishmama/109662624017758418
mastodon.online/@mlepage/109662896325584665
mstdn.social/@acerbicotter/109665734417543743
mastodon.scot/@GuitarMoog/109666494504739267
mstdn.social/@bubbies/109666749746112493

The next logical step is to get the contents of said social media posts, which requires a bit of coding.

To get the original social media posts, you first need to get a Mastodon API token and then read each line in the CSV file, split the ID into its components (server ID, user, toot ID) and grab the social media content with an HTTP GTE request.

A sample script in Python that reads the content of a CSV file and prints out the content of the corresponding social media posts (it uses the Mastodon Python library, which has to be installed first)::

from mastodon import Mastodon, MastodonNotFoundError
import csv

token= '<Mastodon API token>'
file_name= '<downloaded file name and path>'

with open(file_name) as csv_file:
    csv_reader = csv.reader(csv_file, delimiter=',')
    next(csv_reader)
    for line in csv_reader:
        id = line[0].split('/')
        print(f'\n{id}')
        try:
           print(Mastodon(api_base_url=f'https://{id[0]}', 
                         access_token = token).status(id[2])['content'])
        except MastodonNotFoundError:
            print('*** Post not found')
            continue