Skip to main content

Send out messages to Mastodon and Twitter using one simplistic unified API

Project description

📢 MultiToeter

Introduction

MultiToeter is a python library providing a simplified unified API for sending messages to both the Twitter and Mastodon platform at the same time.

Usage

# install through pip
pip install multitoeter

Initialize through autoinit

MultiToeter support initializing your keys and secrets, needed for connecting to the Twitter and Mastodon API, through environment variables or through a .env file. Below are two examples on how to use this. You can mix and match these two methods. The priority is currently to try environment variables first followed by the .env file.

# Simple script to send a message through MultiToeter
# Save as: test.py
from multitoeter import autoinit_multitoeter

mt = autoinit_multitoeter()

toeter = mt.toeter('Testing MultiToeter API autoinit')
toeter = mt.toeter('Reply message', in_reply_to=toeter)
# environment variable example
# only use mastodon in this example
MASTODON_ACCESS_TOKEN=<..> MASTODON_BASE_URL=https://mstdn.science python test.py 
# .env file example
MASTODON_ACCESS_TOKEN=<..>
MASTODON_BASE_URL=https://mstdn.science

TWITTER_CONSUMER_KEY=<..>
TWITTER_CONSUMER_SECRET=<..>
TWITTER_ACCESS_TOKEN=<..>
TWITTER_ACCESS_TOKEN_SECRET=<..>

# Now run test.py:
# python test.py 

Initialize in code

A secondary approach is to initialize MultiToeter in code instead of using the autoinit. This gives you more flexibility and allows you to use more than one account for the same platform should you need it.

from multitoeter import Mastodon, Twitter, MultiToeter

mastodon1 = Mastodon(
  access_token="<..>",
  api_base_url="https://mstdn.science"
)
mastodon2 = Mastodon(
  access_token="<..>",
  api_base_url="https://mstdn.social/"
)

twitter1 = Twitter(
  consumer_key="<..>"
  consumer_secret="<..>"
  access_token="<..>"
  access_token_secret="<..>"
)

multi = MultiToeter({'mastodon1': mastodon1, 'mastodon2': mastodon2, 'twitter': twitter1})

toeter = multi.toeter("Test post via MultiToeter API")
toeter = multi.toeter("Test reply via MultiToeter API", in_reply_to=toeter)

Adding media files

Limited support for media files is available. The unified API expects you to point to the media files directly.

# Assume that the file test.jpg exists
from multitoeter import autoinit_multitoeter

mt = autoinit_multitoeter()

toeter = mt.toeter('Testing MultiToeter API autoinit', media_files=['test.jpg'])

Project details


Release history Release notifications | RSS feed

This version

2

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

multitoeter-2.tar.gz (4.3 kB view details)

Uploaded Source

File details

Details for the file multitoeter-2.tar.gz.

File metadata

  • Download URL: multitoeter-2.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for multitoeter-2.tar.gz
Algorithm Hash digest
SHA256 93677dc7ddfaaafccf524cc47f00da43c801a5dcdc7dc147ac3038abef935d68
MD5 7771ed5f47392f78eb429d316a54958e
BLAKE2b-256 8a3647c27a75a7592c06ccdbbc1ba0f6807329c6adccdec960925a2031fc5bfa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page