Legal Facts Poster (legal-facts-poster)
An Autonomous AI Agent & Browser Automation Worker for Legal Community Feeds
legal-facts-poster is an autonomous AI agent worker that bridges large language model intelligence with headless browser automation. It continuously synthesizes educational legal insights across Indian jurisprudence and publishes them directly to community platforms with native rich HTML formatting, persistent sessions, duplicate prevention memory, and humanized jitter scheduling.
⚡ Quick Install
pip install legal-facts-poster
playwright install chromium
Fast Verification: Test your installation with
legal-post --versionor post an immediate sample insight withpost-once --headless.
What Is This Tool?
legal-facts-poster is an Autonomous AI Agent Worker that unifies three core capabilities:
- The Brain (AI Reasoning Agent): Evaluates past posting history (
posted_history.txt), rotates across core legal domains, and prompts your choice of LLM (Google Gemini, OpenAI, Claude, DeepSeek, Grok, Kimi, Groq, OpenRouter, or local models) to synthesize concise, structured legal insights. - The Hands (Browser Automation Bot): Uses Playwright to authenticate, persist login sessions (
session.json), navigate dynamic platform UIs, insert rich HTML (<strong>,<ul><li>,<em>) into WYSIWYG editors, and select community tags from interactive comboboxes. - The Engine (Autonomous Scheduler & CLI): Operates either as an immediate single-post runner (
post-once) or an autonomous recurring daemon (legal-post) with anti-bot randomized timing jitter (±5–10 min) and auto-retry resilience.
📖 Need a quick cheat-sheet? Check out the complete Command Reference Guide (COMMANDS.md).
Features
- Jurisprudence Domain Rotation: Rotates through core branches of Indian law (Constitutional Law, Criminal Law, Consumer Protection, Cyber Law, Citizen Rights, and Commercial Law).
- Rich Text Formatting: Emits native HTML (
<strong>,<ul><li>,<em>) into the platform's WYSIWYG editor so headlines, bullet lists, and takeaways render with true typography. - Intelligent Tag Sanitizer: Automatically cleans, formats, and deduplicates community hashtags, eliminating compound tag strings.
- Session Persistence: Stores authenticated session state (
session.json) after initial login with secure0600permissions, eliminating repetitive logins and accelerating subsequent post cycles. - Configurable Scheduling with Jitter: Supports custom hourly post intervals with optional humanized jitter (±5–10 minutes) to avoid predictable robot-like posting times.
- Reliability & Auto-Retry: Automatically retries on temporary hiccups with POSIX-standard signal handling (
130/143). - Multi-Channel Alerting: Dispatches instant notifications to Discord (rich embeds), Microsoft Teams (Adaptive Cards v1.4), Telegram, and generic webhooks with automatic token masking.
- Pip & Docker Ready: Officially available on PyPI (
pip install legal-facts-poster) and GitHub Container Registry (ghcr.io).
Installation & Quick Start
1. Official Install via pip (Recommended)
pip install legal-facts-poster
playwright install chromium
Verify your installation:
legal-post --version
2. Isolated CLI Install via uv tool
Install the standalone CLI globally in an isolated virtual environment:
uv tool install legal-facts-poster
playwright install chromium
3. Containerized Deployment via Docker (Zero Local Setup)
Pull and run the pre-built, hardened non-root container from GitHub Container Registry:
docker pull ghcr.io/kumar-swaraj/legal-facts-poster:latest
# Run a single post (headless by default):
docker run --rm --env-file .env ghcr.io/kumar-swaraj/legal-facts-poster:latest post-once
# Or run the autonomous recurring background daemon:
docker run -d --restart unless-stopped --name legal-poster --env-file .env ghcr.io/kumar-swaraj/legal-facts-poster:latest
4. Ephemeral Zero-Install (On-Demand via uvx)
Run directly without installing any package into your environment:
uvx legal-facts-poster post-once --help
5. Local Development (uv / pip)
git clone https://github.com/kumar-swaraj/legal-facts-poster.git
cd legal-facts-poster
uv pip install -e ".[dev]"
uv run playwright install chromium
Configuration
When a user downloads and installs legal-facts-poster, credentials can be supplied via any of the following methods:
Method 1: Interactive Setup Wizard (Recommended)
Run the guided terminal setup wizard with hidden password masking:
legal-config
# or
legal-post config
This prompts for your username, password, Gemini API key, and platform URL, and saves them securely to ~/.config/legal-facts-poster/.env with strict 0600 permissions. Once configured, you can run legal-post from anywhere on your machine!
Method 2: Generate Local .env
Run the template generator in your project folder:
legal-post --init-env
This creates a local .env file template ready for your credentials.
Method 3: Shell Environment Variables
Export variables in your ~/.zshrc or ~/.bashrc:
export MY_SITE_USERNAME="your-email@example.com"
export MY_SITE_PASSWORD="your-password"
export GEMINI_API_KEY="your-gemini-api-key"
export BASE_URL="https://your-platform.com"
Method 4: Custom File Path via --env-file
Pass any custom .env file explicitly at runtime:
legal-post --env-file /path/to/my-secrets.env
Configuration Variables
| Variable | Description | Default |
|---|---|---|
MY_SITE_USERNAME |
Platform account email / username | Required |
MY_SITE_PASSWORD |
Platform account password | Required |
AI_PROVIDER |
AI provider (gemini, openai, claude, deepseek, grok, kimi, groq, openrouter, custom) |
gemini |
AI_API_KEY |
API key for your chosen AI provider | Required |
AI_MODEL |
Optional model name override | Provider default |
AI_BASE_URL |
Optional custom OpenAI-compatible endpoint URL (for Ollama, vLLM, etc.) | Provider default |
BASE_URL |
Target platform base URL (e.g. https://your-platform-domain.com) |
Required |
HEADLESS |
Run browser in background (true or false) |
false |
POST_INTERVAL_HOURS |
Interval in hours between automated posts | 4.0 |
ENABLE_JITTER |
Apply random delay (±5-10m) before posting | true |
JITTER_MAX_MINUTES |
Maximum jitter minutes | 10 |
SESSION_FILE |
File to save authenticated session state | session.json |
HISTORY_FILE |
File to track posted topics to prevent duplicates | posted_history.txt |
MAX_RETRIES |
Retry attempts on network/browser failures | 2 |
RETRY_DELAY_SECONDS |
Delay in seconds between retries | 60 |
WEBHOOK_URL |
Discord, MS Teams, Slack, or generic webhook URL for alerts | "" (Disabled) |
TEAMS_WEBHOOK_URL |
Dedicated Microsoft Teams webhook URL (Adaptive Cards v1.4) | "" (Disabled) |
TELEGRAM_BOT_TOKEN |
Telegram Bot token for direct alert messages | "" (Disabled) |
TELEGRAM_CHAT_ID |
Telegram chat ID to receive alert messages | "" (Disabled) |
NOTIFY_ON |
Alert level: all (posts + errors) or failures_only |
all |
HEALTHCHECK_URL |
Dead-man's switch ping URL (Healthchecks.io) | "" (Disabled) |
Supported AI Providers
You can use any of the following AI providers by setting AI_PROVIDER and your API key:
| Provider | AI_PROVIDER |
Default Model | Get API Key |
|---|---|---|---|
| Google Gemini | gemini |
gemini-3.5-flash |
Google AI Studio |
| OpenAI | openai |
gpt-4o-mini |
OpenAI Platform |
| Anthropic Claude | claude |
claude-3-5-haiku-20241022 |
Anthropic Console |
| DeepSeek | deepseek |
deepseek-chat |
DeepSeek Platform |
| xAI Grok | grok |
grok-2-latest |
xAI Console |
| Moonshot AI (Kimi) | kimi |
moonshot-v1-8k |
Moonshot Platform |
| Groq | groq |
llama-3.3-70b-versatile |
Groq Console |
| OpenRouter | openrouter |
anthropic/claude-3.5-haiku |
OpenRouter |
| Custom / Ollama | custom |
Specified in AI_MODEL |
Local or Self-Hosted |
Usage
1. Publishing a Single Post (Post Once & Exit)
Via direct script:
python post_once.py
# Or headless in background:
python post_once.py --headless
Via CLI command:
post-once
# Or using the flag:
legal-post --once
2. Scheduled Autonomous Posting
Run continuously on default 4-hour schedule (with random jitter):
legal-post
Run in headless mode (background):
legal-post --headless
Run on a custom 2-hour interval:
legal-post -i 2.0
Run N posts then exit:
legal-post -n 5
Show all CLI options:
legal-post --help
Docker & Cloud Deployment
Deploy the autonomous posting daemon 24/7 on a VPS, server, or cloud VM with zero local Python or browser installation:
# 1. Start daemon in background (auto-restarts on reboot)
docker compose up -d
# 2. View live execution logs
docker compose logs -f
# 3. Stop container
docker compose down
Security Hardened: The container image drops root privileges and runs under the unprivileged
pwuseraccount with persistent volume mounts forsession.jsonandposted_history.txt. Pre-built images are published toghcr.io/kumar-swaraj/legal-facts-poster:latest.
Developer Tooling & Quality Checks
This project uses the modern Astral toolchain (uv, pytest, Ruff, MyPy) for zero-friction quality assurance:
# Run automated unit test suite
uv run pytest
# Check code style & linter rules (Ruff)
uv run ruff check . --fix
# Format code (Ruff)
uv run ruff format .
# Check formatting without modifying files
uv run ruff format --check .
# Static type checking across source and tests (MyPy)
uv run mypy src/ tests/
# Full verification suite
uv run ruff check . && uv run ruff format --check . && uv run mypy src/ tests/ && uv run pytest
Project Architecture
legal-facts-poster/
├── .github/
│ ├── dependabot.yml # Automated dependency security scanning
│ └── workflows/
│ ├── ci.yml # Automated CI linting, typing & unit tests
│ └── release.yml # Auto-release & GHCR Docker publish on v* tags
├── Dockerfile # Production non-root container with Playwright
├── docker-compose.yml # Docker service definition with volume persistence
├── COMMANDS.md # Categorized command cheat-sheet
├── SECURITY.md # Security architecture & vulnerability policy
├── LICENSE # MIT Open Source License
├── README.md # Project documentation & guides
├── pyproject.toml # PEP 517/621 package metadata & quality configs
├── .env.example # Environment variables template
├── tests/ # Automated pytest suite (CLI, config, history, categories)
└── src/
└── legal_facts_poster/
├── __init__.py # Package interface & version export (__version__)
├── config.py # Multi-provider environment loading & validation
├── categories.py # Indian law domain definitions & rotation logic
├── history.py # History persistence manager
├── ai_generator.py # Multi-model structured fact generation & HTML formatting
├── browser_bot.py # Playwright browser automation & session persistence (0600)
├── notifier.py # Observability & alerts (Discord embeds, Teams Adaptive Cards, Telegram, webhooks)
├── runner.py # Task orchestration, SIGTERM handling & schedule loop
├── wizard.py # Interactive terminal setup wizard
└── cli.py # CLI argument parsing (argparse) & command dispatcher
Security
Please see SECURITY.md for supported versions, our defense-in-depth security model, and how to report vulnerabilities responsibly.
Metadata
Release files for legal-facts-poster 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| legal_facts_poster-0.1.1.tar.gz | 41.2 kB | With provenance | Details for legal_facts_poster-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| legal_facts_poster-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for legal_facts_poster-0.1.1-py3-none-any.whl |
Total release size: 75.6 kB
Release files / legal_facts_poster-0.1.1.tar.gz
| Download URL | legal_facts_poster-0.1.1.tar.gz |
|---|---|
| Size | 41.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
41bc6d3424c6128abcfdf7264aa5c0ed84427f61918b16d90067fb67f5e8b0ac
|
|
BLAKE2b-256 checksum How to use checksums |
08faf592fe285f3ec76696193552d16b78ef546fb3123f074f7c45e87d4064b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.
Transparency logRelease files / legal_facts_poster-0.1.1-py3-none-any.whl
| Download URL | legal_facts_poster-0.1.1-py3-none-any.whl |
|---|---|
| Size | 34.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
35844e27411a9be2ef8cf9703e85dbc5d1d35c2be2596c69cadb422fbeecef77
|
|
BLAKE2b-256 checksum How to use checksums |
d800042b7f24e3877cc563ba97eb7605b3499f59e9f67493eb5e72984a734906
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.
Transparency logSecurity for legal-facts-poster 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for legal_facts_poster-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 22, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.