|
| 1 | +#!/usr/bin/env python3 |
| 2 | + |
| 3 | +# Python3 script to print the current date and time, using |
| 4 | +# the Adafruit_Thermal library, in ISO 8601 format. |
| 5 | +# https://www.iso.org/iso-8601-date-and-time-format.html |
| 6 | + |
| 7 | +import time |
| 8 | +from Adafruit_Thermal import * |
| 9 | + |
| 10 | +# Lines of margin (integer) |
| 11 | +i_feed = 3 |
| 12 | +# Seconds to pause (float) |
| 13 | +f_pause = 1.0 |
| 14 | + |
| 15 | +# Define the printer port, speed, and timeout |
| 16 | +printer = Adafruit_Thermal("/dev/ttyS0", 19200, timeout=5) |
| 17 | + |
| 18 | +# Build the date stamp in the format YYYY-MM-DD ex: "2021-12-25" |
| 19 | +datestamp = time.strftime("%Y-%m-%d", time.gmtime()) |
| 20 | +print ("Date in preferred format:", datestamp) |
| 21 | + |
| 22 | +# Build the time stamp in the format Thh:mm:ssZ ex: "T23:59:59Z" |
| 23 | +timestamp = 'T' + time.strftime("%H:%M:%S", time.gmtime()) + 'Z' |
| 24 | +print ("Time in preferred format:", timestamp) |
| 25 | + |
| 26 | +# Tell printer to sleep |
| 27 | +printer.sleep() |
| 28 | +# Sleep for the defined time in case we're called many times in a row |
| 29 | +time.sleep(f_pause) |
| 30 | +# Call wake() before printing again, even if reset |
| 31 | +printer.wake() |
| 32 | +# Restore printer to defaults |
| 33 | +printer.setDefault() |
| 34 | + |
| 35 | +# Give a little room at the top |
| 36 | +printer.feed(i_feed) |
| 37 | +# Center justify |
| 38 | +printer.justify('C') |
| 39 | +# Large size |
| 40 | +printer.setSize('L') |
| 41 | +# Print the date |
| 42 | +printer.println(datestamp) |
| 43 | +# Print the time |
| 44 | +printer.println(timestamp) |
| 45 | +# Give a little room at the bottom |
| 46 | +printer.feed(i_feed) |
0 commit comments