34 lines
813 B
Python
34 lines
813 B
Python
|
A
|
#!/usr/bin/env python3
|
||
|
|
"""Export all subscribers to JSON on stdout."""
|
||
|
|
import json
|
||
|
|
import os
|
||
|
|
import sys
|
||
|
|
from datetime import datetime, timezone
|
||
|
|
|
||
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
||
|
|
|
||
|
|
from server.database import export_all, get_connection
|
||
|
|
from server.utils import load_config
|
||
|
|
|
||
|
|
|
||
|
|
def main():
|
||
|
|
config_path = os.environ.get("CONFIG_PATH", "config.yaml")
|
||
|
|
cfg = load_config(config_path)
|
||
|
|
|
||
|
|
conn = get_connection(cfg["database"]["path"])
|
||
|
|
try:
|
||
|
|
subscribers = export_all(conn)
|
||
|
|
finally:
|
||
|
|
conn.close()
|
||
|
|
|
||
|
|
output = {
|
||
|
|
"exported_at": datetime.now(timezone.utc).isoformat(),
|
||
|
|
"count": len(subscribers),
|
||
|
|
"subscribers": subscribers,
|
||
|
|
}
|
||
|
|
print(json.dumps(output, indent=2, default=str))
|
||
|
|
|
||
|
|
|
||
|
|
if __name__ == "__main__":
|
||
|
|
main()
|