better rotation

This commit is contained in:
Joe Lothan 2026-06-15 17:12:25 -04:00
parent 5488773d39
commit 96d2af4c3f

View file

@ -4,9 +4,9 @@
Reads a CSV of trades (timestamp, symbol, lots, price) and generates
ESC/POS commands with 90° rotated text to emulate an old stock ticker tape.
When the receipt paper is turned sideways:
- Symbol appears at the top of the tape
- Price (and lot count) appears at the bottom
Each character gets its own printed row. When the receipt paper is turned
sideways, symbol characters read across the top and price characters read
across the bottom just like a real ticker tape.
"""
import csv
@ -18,21 +18,23 @@ from escpos.printer import Dummy
LINE_WIDTH = 42
def format_trade(symbol, lots, price):
"""Format a trade line for the ticker tape.
Symbol is placed at the start of the line, price info at the end.
With 90° rotation, start-of-line = top of tape, end-of-line = bottom.
"""
def print_trade(p, symbol, lots, price):
"""Print a single trade as ticker tape characters, one per row."""
if lots > 1:
price_str = f"{lots}s{price:.2f}"
else:
price_str = f"{price:.2f}"
padding = LINE_WIDTH - len(symbol) - len(price_str)
if padding < 1:
padding = 1
return symbol + " " * padding + price_str
# Symbol characters at the top (left-aligned)
for ch in symbol:
p.text(ch + "\n")
# Price characters at the bottom (right-aligned)
for ch in price_str:
p.text(" " * (LINE_WIDTH - 1) + ch + "\n")
# Blank line separator between trades
p.text("\n")
def main():
@ -50,8 +52,7 @@ def main():
_timestamp, symbol, lots_str, price_str = row
lots = int(lots_str)
price = float(price_str)
line = format_trade(symbol, lots, price)
p.text(line + "\n")
print_trade(p, symbol, lots, price)
p.cut()