-
Notifications
You must be signed in to change notification settings - Fork 0
/
gm
executable file
·42 lines (32 loc) · 1.32 KB
/
gm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python3
import argparse
import json
import time
from pathlib import Path
def gm():
parser = argparse.ArgumentParser(description="Generate JSON global messages.")
parser.add_argument("env", choices=["prod", "next", "localdev"], help="Environment: prod, next, or localdev.")
parser.add_argument("severity", choices=["success", "info", "warning", "error"], help="Message severity level.")
parser.add_argument("message", nargs="?", default="", help="Message. If empty, it will clear the message.")
parser.add_argument("--sign", metavar="Username", help="Optionally sign the message with a name.")
args = parser.parse_args()
if args.message:
message = args.message
if args.sign:
message += f' -- <a href="https://couchers.org/user/{args.sign.lower()}">{args.sign}</a>'
content = {
"epoch": str(int(time.time() * 1000)),
"severity": args.severity,
"message": message
}
else:
content = {
"epoch": "",
"severity": "success",
"message": ""
}
output_file = Path(__file__).parent / "nginx" / "gm" / f"{args.env}.json"
output_file.write_text(json.dumps(content, indent=2))
print(f"Global message written to {output_file}")
if __name__ == "__main__":
gm()