A Python-based client for interacting with Mastodon instances, supporting app registration, posting, and managing toots. This project integrates Google Cloud services for secret management and logging, facilitating robust deployment and operation.
Features
- Register Mastodon applications with customizable scopes and redirect URIs.
- Retrieve and update posts (toots) via REST API endpoints.
- Integration with Google Cloud Secret Manager for secure credential storage.
- Google Cloud Logging integration for centralized log management.
- Dockerized for containerized deployment.
Tech Stack
- Python 3.6+
- Mastodon.py (Mastodon API client)
- Google Cloud Secret Manager
- Google Cloud Logging
- Requests (HTTP client)
- Docker
Getting Started
Prerequisites
- Python 3.6 or higher
- Google Cloud SDK installed and authenticated
- Docker (optional, for containerized usage)
Installation
Clone the repository and set up a virtual environment:
git clone https://github.com/justin-napolitano/mastodon-client.git
cd mastodon-client
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install -r requirements.txt
Configuration
- Create a
.envfile in the root directory (if needed):
PROJECT_NAME=your_google_cloud_project_id
- Store the following secrets in Google Cloud Secret Manager:
MASTODON_PASSWORDMASTODON_USERNAMEMASTODON_CLIENT_IDMASTODON_SECRETMASTODON_BASE_URLMASTODON_USER_AGENT
Usage
Run the main scripts or utilities as needed:
- Register a Mastodon app:
python mastodon-app-registration.py --api_base_url mastodon.social
- Retrieve a new post:
python get_post.py --table toots --url http://localhost:8080
- Run the Mastodon client script (adjust URL and flags as needed):
python mastodon-client.py --url http://localhost:8080
Docker Build and Push
Build and push the Docker image using the provided Cloud Build config:
gcloud builds submit --config cloudbuild.yaml .
Project Structure
mastodon-client/
βββ cloudbuild.yaml # Google Cloud Build configuration
βββ Dockerfile # Docker image build instructions
βββ gcputils/ # Google Cloud utility submodule
β βββ GoogleCloudLogging.py
β βββ GoogleSecretManager.py
β βββ gcpclient.py
β βββ BigQueryClient.py
βββ get_post.py # Script to retrieve posts from API
βββ mastodon-app-registration.py # App registration utility
βββ mastodon-client.py # Main Mastodon client script
βββ requirements.txt # Python dependencies
βββ readme.md # This README file
βββ sql/ # SQL schema files
β βββ mastodon-table.sql
βββ test-update-toots.sh # Shell script for testing toot updates
Future Work / Roadmap
- Expand support for more Mastodon API endpoints and features.
- Add comprehensive error handling and retry logic.
- Implement automated tests and CI/CD pipelines.
- Enhance documentation with usage examples and API references.
- Support OAuth flows with redirect URIs.
- Integrate BigQuery data analytics on stored toot data.
- Improve Docker image for production readiness.
For questions or contributions, please open an issue or pull request on GitHub.