Fix borked toml_teaprint for python-escpos 3.1.
Updated and it wasn't working, which makes it hard to put labels on all my new tea!
This commit is contained in:
parent
fcc6765a16
commit
377e4c03c7
|
@ -6,19 +6,15 @@ import subprocess
|
|||
|
||||
from escpos.printer import File
|
||||
|
||||
p = File('/dev/usb/lp0')
|
||||
printer = File("/dev/usb/lp0")
|
||||
|
||||
# Garbage params
|
||||
columns = 42
|
||||
lnbreak = '-' * columns
|
||||
lnbreak = "-" * columns
|
||||
|
||||
# Setup args.
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument(
|
||||
'file',
|
||||
help='Input files',
|
||||
type=argparse.FileType(mode='rb')
|
||||
)
|
||||
parser.add_argument("file", help="Input files", type=argparse.FileType(mode="rb"))
|
||||
args = parser.parse_args()
|
||||
|
||||
|
||||
|
@ -27,15 +23,15 @@ def layout(item):
|
|||
Maker: {factory}
|
||||
Tea: {style}
|
||||
Category: {category}
|
||||
""".format(**item, lnbreak=lnbreak)
|
||||
""".format(
|
||||
**item, lnbreak=lnbreak
|
||||
)
|
||||
|
||||
|
||||
# Get fortune
|
||||
def fort(cols):
|
||||
out = subprocess.run(
|
||||
['fortune', '-sn', str(cols)],
|
||||
capture_output=True,
|
||||
universal_newlines=True
|
||||
["fortune", "-sn", str(cols)], capture_output=True, universal_newlines=True
|
||||
)
|
||||
out = str(out.stdout).strip("\n")
|
||||
return out
|
||||
|
@ -43,12 +39,16 @@ def fort(cols):
|
|||
|
||||
# Fast reset for printer.
|
||||
def reset():
|
||||
p.set(
|
||||
align='left', font='left',
|
||||
text_type='NORMAL',
|
||||
height=1, width=1, density=1
|
||||
printer.set(
|
||||
align="left",
|
||||
font=1,
|
||||
bold=0,
|
||||
normal_textsize=1,
|
||||
height=1,
|
||||
width=1,
|
||||
density=1,
|
||||
)
|
||||
p.charcode('multilingual')
|
||||
# printer.charcode("multilingual")
|
||||
|
||||
|
||||
# Process TOML into dictionary
|
||||
|
@ -56,28 +56,34 @@ toml = tomli.load(args.file)
|
|||
|
||||
for x in toml:
|
||||
tea = {
|
||||
'year': str(toml[x]['year']),
|
||||
'factory': toml[x]['factory'],
|
||||
'style': toml[x]['style'],
|
||||
'category': toml[x]['category']
|
||||
"year": str(toml[x]["year"]),
|
||||
"factory": toml[x]["factory"],
|
||||
"style": toml[x]["style"],
|
||||
"category": toml[x]["category"],
|
||||
}
|
||||
fortune = fort(columns)
|
||||
line = layout(tea)
|
||||
|
||||
# Start printing
|
||||
p.set(
|
||||
align='left', font='center',
|
||||
text_type='NORMAL',
|
||||
height=1, width=2, density=3
|
||||
printer.set(
|
||||
align="left",
|
||||
font=0,
|
||||
bold=0,
|
||||
height=1,
|
||||
width=2,
|
||||
density=3,
|
||||
)
|
||||
p.text(line)
|
||||
p.set(
|
||||
align='center', font='left',
|
||||
text_type='B',
|
||||
height=1, width=1, density=3
|
||||
printer.text(line)
|
||||
printer.set(
|
||||
align="center",
|
||||
font=1,
|
||||
bold=0,
|
||||
height=1,
|
||||
width=1,
|
||||
density=3,
|
||||
)
|
||||
p.text(lnbreak + '\n')
|
||||
p.text(fortune + '\n')
|
||||
p.text(lnbreak + '\n')
|
||||
p.cut()
|
||||
printer.text(lnbreak + "\n")
|
||||
printer.text(fortune + "\n")
|
||||
printer.text(lnbreak + "\n")
|
||||
printer.cut()
|
||||
reset()
|
||||
|
|
Loading…
Reference in New Issue