forked from vycdev/thermal-printer-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdispatch_print.py
More file actions
168 lines (144 loc) · 5.18 KB
/
Copy pathdispatch_print.py
File metadata and controls
168 lines (144 loc) · 5.18 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env python3
"""Print a fictional field dispatch on the S01 thermal printer.
This is an original self-contained script. It generates a compact mission
report from the static: location, conditions, anomaly, directive, and a short
status tag. A small map glyph keeps the receipt visually distinctive.
Examples:
python dispatch_print.py
python dispatch_print.py --seed 20240613
python dispatch_print.py --no-print
"""
from __future__ import annotations
import argparse
from dataclasses import dataclass
from datetime import datetime
from pathlib import Path
import random
from PIL import Image, ImageDraw
from print_common import ROOT, Card, font
@dataclass(frozen=True)
class Dispatch:
sector: str
conditions: str
anomaly: str
directive: str
status: str
code: str
SECTORS = [
"Sector 4 / Dusk Grid",
"North Relay Ridge",
"Old Harbor Line",
"Paper Mill District",
"Glass Flats",
"Cinder Loop",
"Sublevel 12",
"The Quiet Mile",
]
CONDITIONS = [
"low wind, clear edges",
"thin fog, stable pressure",
"warm static, no rain",
"overcast, bright horizon",
"cold air, clean sightlines",
"heavy cloud, soft ground",
"night calm, faint hum",
"dust in the light path",
]
ANOMALIES = [
"A signal repeats every 11 seconds.",
"Something moved before the sensor woke up.",
"One route marker is pointing the wrong way.",
"The shadow is slightly delayed.",
"A distant light keeps answering back.",
"The map has one extra road.",
"The quiet corner is making noise.",
"A forgotten machine is still warm.",
]
DIRECTIVES = [
"Verify the source before you follow it.",
"Do not trust the first reflection.",
"Take the longer path if it stays honest.",
"Record anything that feels too exact.",
"Leave the door open when you leave.",
"If it blinks twice, step back.",
"Keep the useful tool in reach.",
"Bring back the smallest proof.",
]
STATUSES = [
"contained",
"watching",
"unresolved",
"stable",
"quiet",
"pending",
"noted",
"rechecked",
]
def build_dispatch(rng: random.Random) -> Dispatch:
code = "-".join(
[
rng.choice(["ALPHA", "BRAVO", "CINDER", "EMBER", "KILO", "LANTERN"]),
f"{rng.randrange(10, 99)}",
f"{rng.randrange(100, 999)}",
]
)
return Dispatch(
sector=rng.choice(SECTORS),
conditions=rng.choice(CONDITIONS),
anomaly=rng.choice(ANOMALIES),
directive=rng.choice(DIRECTIVES),
status=rng.choice(STATUSES),
code=code,
)
def draw_map(size: int = 150) -> Image.Image:
"""Draw a simple map pin / compass glyph."""
img = Image.new("L", (size, size), 255)
d = ImageDraw.Draw(img)
cx = cy = size / 2
r = size * 0.34
d.ellipse((cx - r, cy - r, cx + r, cy + r), outline=0, width=2)
d.line((cx, cy - r + 8, cx, cy + r - 8), fill=0, width=2)
d.line((cx - r + 8, cy, cx + r - 8, cy), fill=0, width=2)
d.polygon([(cx, cy - 8), (cx + 8, cy + 8), (cx - 8, cy + 8)], fill=0)
d.ellipse((cx - 12, cy - 12, cx + 12, cy + 12), outline=0, width=2)
d.line((cx - 26, cy + 28, cx + 26, cy - 28), fill=0, width=1)
d.line((cx - 19, cy - 25, cx - 10, cy - 16), fill=0, width=1)
d.line((cx + 10, cy + 16, cx + 19, cy + 25), fill=0, width=1)
return img
def main() -> int:
parser = argparse.ArgumentParser(description="Print a fictional field dispatch on the S01 thermal printer.")
parser.add_argument("--seed", type=int, default=None, help="Seed for reproducible dispatches.")
parser.add_argument("--out", type=Path, default=ROOT / "dispatch.png")
parser.add_argument("--darkness", type=int, choices=range(1, 6), default=3)
parser.add_argument("--bottom-feed", type=int, default=24)
parser.add_argument("--no-print", action="store_true")
args = parser.parse_args()
seed = args.seed if args.seed is not None else random.randrange(1, 1_000_000)
rng = random.Random(seed)
d = build_dispatch(rng)
print(f"Dispatch seed: {seed}")
print(f" sector: {d.sector}")
print(f" conditions: {d.conditions}")
print(f" anomaly: {d.anomaly}")
print(f" directive: {d.directive}")
print(f" status: {d.status}")
print(f" code: {d.code}")
card = Card()
card.title("FIELD DISPATCH")
card.gap(2).para("Transmit by hand if needed.", size=13, bold=False, center=True)
card.gap(6).image(draw_map(), border=False)
card.gap(4).divider()
card.gap(5).line("REPORT", size=13, bold=True, center=True)
card.gap(3).para(d.sector, size=17, bold=True, center=True)
card.gap(2).para(f"Conditions: {d.conditions}", size=14, bold=False, center=True)
card.gap(4).divider()
card.para(d.anomaly, size=15, bold=True, center=True)
card.gap(4).para(d.directive, size=15, bold=False, center=True)
card.gap(4).divider()
card.kv("Status", d.status.title(), size=14)
card.kv("Code", d.code, size=14)
card.kv("Time", datetime.now().strftime("%H:%M"), size=14)
card.footer("keep it quiet", "field dispatch")
return card.finish(args.out, args.bottom_feed, args.darkness, do_print=not args.no_print)
if __name__ == "__main__":
raise SystemExit(main())