Reorganize repository into pc web shared monorepo
Separate the local recognition, web publishing, and shared data paths while preserving direct script execution and existing site content. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
"""Two-pass keyzoo helper: stash Feishu URL then run notify with Cloudflare.
|
||||
|
||||
Pass 1 (feishu asset): python _notify_pass_feishu.py stash
|
||||
Pass 2 (cloudflare): python _notify_pass_feishu.py run [--day ...] [--dry-run]
|
||||
|
||||
Temp file is user-only and deleted after run.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import stat
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
STASH = Path(os.environ.get("TEMP") or os.environ.get("TMP") or ".") / "climperor_feishu_wh.url"
|
||||
GITEA_STASH = Path(os.environ.get("TEMP") or os.environ.get("TMP") or ".") / "climperor_gitea.tok"
|
||||
|
||||
|
||||
def stash() -> None:
|
||||
url = os.environ.get("KEYZOO_ASSET_SECRET_FEISHU_WEBHOOK_URL") or os.environ.get(
|
||||
"FEISHU_WEBHOOK_URL"
|
||||
)
|
||||
if not url:
|
||||
raise SystemExit("no feishu webhook in env")
|
||||
STASH.write_text(url, encoding="utf-8")
|
||||
try:
|
||||
os.chmod(STASH, stat.S_IRUSR | stat.S_IWUSR)
|
||||
except OSError:
|
||||
pass
|
||||
print(f"stashed webhook -> {STASH.name} ({STASH.exists()})")
|
||||
|
||||
|
||||
def run(argv: list[str]) -> int:
|
||||
if not STASH.exists():
|
||||
raise SystemExit(f"missing stash {STASH}; run pass1 first")
|
||||
url = STASH.read_text(encoding="utf-8").strip()
|
||||
try:
|
||||
STASH.unlink()
|
||||
except OSError:
|
||||
pass
|
||||
os.environ["FEISHU_WEBHOOK_URL"] = url
|
||||
if GITEA_STASH.exists():
|
||||
tok = GITEA_STASH.read_text(encoding="utf-8").strip()
|
||||
try:
|
||||
GITEA_STASH.unlink()
|
||||
except OSError:
|
||||
pass
|
||||
if tok:
|
||||
os.environ["GITEA_TOKEN"] = tok
|
||||
# Import after env is set
|
||||
import notify_site_traffic as n
|
||||
|
||||
return n.main(argv)
|
||||
|
||||
|
||||
def main() -> int:
|
||||
ap = argparse.ArgumentParser()
|
||||
ap.add_argument("cmd", choices=("stash", "run"))
|
||||
ap.add_argument("--day")
|
||||
ap.add_argument("--dry-run", action="store_true")
|
||||
args, rest = ap.parse_known_args()
|
||||
if args.cmd == "stash":
|
||||
stash()
|
||||
return 0
|
||||
argv: list[str] = []
|
||||
if args.day:
|
||||
argv += ["--day", args.day]
|
||||
if args.dry_run:
|
||||
argv += ["--dry-run"]
|
||||
argv += rest
|
||||
return run(argv)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user