Files
pravda/main.py
Steve Dudenhoeffer c75856ff44
Some checks failed
Build and Push Docker Image / build (push) Failing after 1m59s
Implement Pravda: Truth Social to Discord relay service
- Add core modules: database (SQLite), media (ffmpeg), discord (webhook), poller (truthbrush), server (FastAPI)
- Support video transcoding to H.264/AAC with automatic size management
- Handle message splitting for Discord limits (2000 chars, 10 attachments)
- Include interactive buttons (Delete, View Raw, Original Post)
- Add Dockerfile with ffmpeg and entrypoint script
- Add Gitea Actions workflow for CI/CD
- Configure code style tools (black, ruff, mypy)
- Include basic unit tests

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-23 01:01:59 -05:00

66 lines
1.5 KiB
Python

#!/usr/bin/env python3
"""
Pravda - Truth Social to Discord relay service.
This is the main entrypoint that runs both the poller and the FastAPI server.
"""
import multiprocessing
import sys
import uvicorn
from src.poller import fetch_and_relay_post, poll_loop
from src.server import app
def run_server() -> None:
"""Run the FastAPI server."""
uvicorn.run(app, host="0.0.0.0", port=8080, log_level="info")
def run_poller() -> None:
"""Run the polling loop."""
poll_loop()
def daemon_mode() -> None:
"""Run both the poller and server concurrently."""
print("Starting Pravda in daemon mode...")
# Start server in a separate process
server_process = multiprocessing.Process(target=run_server, name="server")
server_process.start()
# Run poller in the main process
try:
run_poller()
except KeyboardInterrupt:
print("\nShutting down...")
finally:
server_process.terminate()
server_process.join(timeout=5)
def oneoff_mode(url: str) -> int:
"""Relay a single post by URL."""
print(f"One-off mode: relaying {url}")
success = fetch_and_relay_post(url)
return 0 if success else 1
def main() -> int:
"""Main entrypoint."""
if len(sys.argv) > 1:
# One-off mode: relay a specific post
url = sys.argv[1]
return oneoff_mode(url)
else:
# Daemon mode: run poller + server
daemon_mode()
return 0
if __name__ == "__main__":
sys.exit(main())