![]() Our updated mastodon_helper.py will look like this. add a description to the image, to make our bot accessible to people who rely on screen readers and other assistive technology.This will be a three-step process, as we need to do the following: We’re able to post some text, great work so far! Let’s see if we can also upload an image. You can also print a response from the API and check for any helpful error messages. If you’re not seeing the post, make sure your the values saved in your. Now you can run python3 bot.py and behold, our bot’s first tweet. Mastodon = Mastodon(access_token=os.environ.get("MASTODON_ACCESS_TOKEN"), api_base_url=os.environ.get("MASTODON_INSTANCE"), request_timeout=100)Īnd then in bot.py: from mastodon_helper import * Now, let’s make our bot post out some text to make sure things are working correctly. MASTODON_ACCESS_TOKEN="123-ABCDEFGHIJKLMNOP" env, with a dot at the beginning of the file name.Īnd in this file we will put the URL of the instance our bot will be posting on and also the access token from our Mastodon app. There’s a few other ways to handle API keys depending on how you’re hosting the bot, and I will touch on this a bit more later on. Note that I’ve added the python-dotenv package to help us manage our API keys from the first step. To reinstall the required packages later, you can run: pip3 install -r requirements.txt pip3 install Mastodon.py seaborn matplotlib numpy pandas python-dotenvĪnd then let’s save our dependencies so that we can install them again when we need to. Splitting the code into parts will make it easier to update and maintain it as we add more features.īefore we start writing code, let’s install a few dependencies. make_chart.py - here we will create a chart from our data.get_data.py - in here we will load and process the data for our chart.mastodon_helper.py - here we can add a few helper functions to keep our main bot.py script tidier.bot.py - this will be our main script that brings everything together.I’m going to start by creating four blank Python files. Once that’s taken care of, it’s time to set up a structure for our project. And you can find the finished project files on my GitHub. If you run into any issues during this step, or at any other point, be sure to join other creative botmakers over at. This is all covered in this tutorial on Botwiki. We are also going to be using the Mastodon.py library to interact with Mastodon’s API.įirst step will be creating an account for our bot and creating an app. I am going to use Python so that we can get access for some common Python libraries for working with data, including pandas and seaborn. In this tutorial I will walk you through a process of recreating one of my bots. These two bots are open-sourced on Glitch, and for more examples, check out a collection of dataviz bots over on Botwiki.
0 Comments
Leave a Reply. |