Skip to content

Commit 0667533

Browse files
committed
Improve datetime.py script and README.md documentation with comments and tips from linting
1 parent 1fe39ca commit 0667533

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ Install Raspbian Buster and Wire the printer according to [this](https://learn.a
88

99
Run a test to see if the printer is working by punching in these commands into the terminal.
1010

11-
```
11+
``` shell
1212
stty -F /dev/serial0 19200
1313
echo -e "This is a test.\\n\\n\\n" > /dev/serial0
1414
```
1515

1616
### Installing
1717

18-
Update the system and install prequisities.
18+
Update the system and install prerequisites.
1919

20-
```
20+
``` shell
2121
sudo apt-get update
2222
sudo apt-get install git cups wiringpi build-essential libcups2-dev libcupsimage2-dev python3-serial python-pil python-unidecode
2323
```
2424

2525
Install the printer driver. Don't worry about the warnings that g++ gives.
2626

27-
```
27+
``` shell
2828
git clone https://github.com/adafruit/zj-58
2929
cd zj-58
3030
make
@@ -33,14 +33,14 @@ sudo ./install
3333

3434
Make the printer the default printer. This is useful if you are going to be doing other things with it.
3535

36-
```
36+
``` shell
3737
sudo lpadmin -p ZJ-58 -E -v serial:/dev/serial0?baud=19200 -m zjiang/ZJ-58.ppd
3838
sudo lpoptions -d ZJ-58
3939
```
4040

4141
Restart the system. Clone this repository and try to run *printertest.py*.
4242

43-
```
43+
``` shell
4444
git clone https://github.com/galacticfan/Python-Thermal-Printer/
4545
cd Python-Thermal-Printer
4646
python3 printertest.py
-15.2 KB
Binary file not shown.

datetime.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,37 @@
1-
#!/usr/bin/python3
2-
# pylint: disable=E1101,W0614
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
36

47
import time
58
from Adafruit_Thermal import *
69

10+
# Lines of margin (integer)
711
i_feed = 3
12+
# Seconds to pause (float)
813
f_pause = 1.0
914

10-
printer = Adafruit_Thermal("/dev/serial0", 19200, timeout=5)
15+
# Define the printer port, speed, and timeout
16+
printer = Adafruit_Thermal("/dev/ttyS0", 19200, timeout=5)
1117

18+
# Build the date stamp in the format YYYY-MM-DD ex: "2021-12-25"
1219
datestamp = time.strftime("%Y-%m-%d", time.gmtime())
1320
print ("Date in preferred format:", datestamp)
21+
22+
# Build the time stamp in the format Thh:mm:ssZ ex: "T23:59:59Z"
1423
timestamp = 'T' + time.strftime("%H:%M:%S", time.gmtime()) + 'Z'
1524
print ("Time in preferred format:", timestamp)
1625

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+
1735
# Give a little room at the top
1836
printer.feed(i_feed)
1937
# Center justify
@@ -26,13 +44,3 @@
2644
printer.println(timestamp)
2745
# Give a little room at the bottom
2846
printer.feed(i_feed)
29-
30-
# Tell printer to sleep
31-
printer.sleep()
32-
# Call wake() before printing again, even if reset
33-
printer.wake()
34-
# Restore printer to defaults
35-
printer.setDefault()
36-
37-
# Sleep for one second in case we're called many times
38-
time.sleep(f_pause)

0 commit comments

Comments
 (0)