From 96d2af4c3f8a0bdf94f546795261b60c849a9829 Mon Sep 17 00:00:00 2001 From: Joe Lothan Date: Mon, 15 Jun 2026 17:12:25 -0400 Subject: [PATCH] better rotation --- print_tape.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/print_tape.py b/print_tape.py index a768139..f3aa2d6 100644 --- a/print_tape.py +++ b/print_tape.py @@ -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()