#!/usr/bin/env python3 """Start the docs crawl with a webhook, once a day (Ujeebu Crawl API). The free quote gives the most the crawl can cost; the job is capped there with max_credits. Run it from cron, for example every morning at 6:00: 0 6 * * * cd /srv/kb && UJEEBU_API_KEY=your-key WEBHOOK_URL=https://kb.example.com/hooks/crawl python3 start_crawl.py The Idempotency-Key makes a retry on the same day return the same job instead of starting another. """ import datetime import os import requests API_KEY = os.environ.get("UJEEBU_API_KEY", "YOUR_API_KEY") API = "https://api.ujeebu.com" WEBHOOK_URL = os.environ.get("WEBHOOK_URL", "https://kb.example.com/hooks/crawl") # your receiver crawl = { "urls": ["https://ujeebu.com/docs"], "scope": {"include": ["/docs/**"], "max_pages": 20}, "use_sitemap": True, "format": "markdown", "markdown": {"filter": "fit"}, "webhook": {"url": WEBHOOK_URL}, } headers = {"ApiKey": API_KEY} def post(path, body, extra_headers=None): response = requests.post(API + path, json=body, headers={**headers, **(extra_headers or {})}, timeout=60) if response.status_code >= 400: raise SystemExit(f"{path}: {response.status_code} {response.text}") return response.json() quote = post("/crawl/quote", crawl) job = post("/crawl", {**crawl, "max_credits": quote["credits_ceiling"]}, {"Idempotency-Key": f"docs-refresh-{datetime.date.today()}"}) print(f"at most {quote['credits_ceiling']} credits:", job)