I have a new home on the Fediverse and want to cross-post on Twitter and Pleroma. Here is a description of how I built my own Twitter-Pleroma bot.
I used Angus Young’s description on how to build a Raspberry Pi Twitter Bot as the starting point. I only had to add a few lines of code to turn it into a Twitter-Pleroma Bot. Below is the Python code, which is divided into two files: post.py and auth.py.
post.py
# Cross-post text on Twitter and Pleroma # The heavy lifting is done by Requests and Twython from twython import Twython from auth import ( twitter_consumer_key, twitter_consumer_secret, twitter_access_token, twitter_access_token_secret, pleroma_domain_name, pleroma_access_token ) twitter = Twython( twitter_consumer_key, twitter_consumer_secret, twitter_access_token, twitter_access_token_secret ) # Example text text = 'Hello World!' # Send the text to Twitter twitter.update_status(status=text) # Send the text to Pleroma url = pleroma_domain_name + '/api/v1/statuses' data = {'status': text} headers = {'Authorization': 'Bearer ' + pleroma_access_token} r = requests.post(url=url, data=data, headers=headers)
auth.py
# Authorization for Twitter and Pleroma twitter_consumer_key = 'XXX' twitter_consumer_secret = 'XXX' twitter_access_token = 'XXX' twitter_access_token_secret = 'XXX' pleroma_domain_name = 'https://XXX' pleroma_access_token = 'XXX'
The authorization codes are obtained by registering the Twitter-Pleroma Bot. Angus Young describes how to register a Twitter App and Darius Kazemi describes how to register a Mastodon App. Kazemi’s description works for Pleroma too!
That’s it!
Related post:
Welcom to my new home on the Fediverse
Leave a Reply
You must be logged in to post a comment.