-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcat_print.py
More file actions
33 lines (25 loc) · 1.21 KB
/
Copy pathcat_print.py
File metadata and controls
33 lines (25 loc) · 1.21 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
#!/usr/bin/env python3
"""Print a random cat photo (thecatapi.com) on the S01 thermal printer."""
from __future__ import annotations
import argparse
from datetime import datetime
from pathlib import Path
from print_common import ROOT, Card, fit_dither, get_bytes, get_json
def main() -> int:
parser = argparse.ArgumentParser(description="Print a random cat on the S01 thermal printer.")
parser.add_argument("--out", type=Path, default=ROOT / "cat.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()
print("Fetching a random cat ...")
meta = get_json("https://api.thecatapi.com/v1/images/search")[0]
img = fit_dither(get_bytes(meta["url"]), Card().inner_w, 360, contrast=1.1)
card = Card()
card.title("RANDOM CAT")
card.image(img)
card.line("- meow -", size=14, bold=False, center=True)
card.footer("thecatapi.com", datetime.now().strftime("%Y-%m-%d %H:%M"))
return card.finish(args.out, args.bottom_feed, args.darkness, do_print=not args.no_print)
if __name__ == "__main__":
raise SystemExit(main())