Teaprint no longer needed due to toml_teaprint

Flowerfetch behavior improved, Xon behavior improved.
This commit is contained in:
Josh 2023-04-03 10:10:05 -04:00
parent 4fc4066213
commit e7491760d8
6 changed files with 66 additions and 80 deletions

2
f16.py
View file

@ -1,4 +1,4 @@
#!/bin/python3.8
#!/bin/python3
import sys

View file

@ -1,4 +1,5 @@
c _ _
c
 _ _
(_\_)
(_ <_{}
(_/_) 

View file

@ -2,7 +2,6 @@
local lfs = require("lfs")
local luadir = arg[0]:match("@?(.*/)");
-- Print out flower from text file
@ -15,11 +14,6 @@ else
os.exit(-1);
end
for filename in lfs.dir("/sys/class/power_supply") do
if filename ~= "." and filename ~= ".." and filename ~= "AC" then
end
end
function Getfile(loc, perm, splitstr, strip)
local table = {};
local gotfile = io.open(loc, perm);

View file

@ -1,65 +0,0 @@
#!/usr/bin/bash
# Input text format is..
# Year|Factory|Tea name|Category
ALIGN="LEFT"
FONT="LEFT"
TEXTYP="NORMAL"
WIDTH=1
HEIGHT=1
DENSITY=1
PRINTLEN=42
LNBREAK=""
LNBREAK=$(awk -v count=$PRINTLEN 'BEGIN { OFS="~"; $(count+1)="";print}')
setnorms () {
python-escpos set --align "left" --font "left" --text_type "NORMAL" \
--height 1 --width 1 --density 1
}
fort () {
python-escpos set --align "center" --font "left" --text_type "B" \
--height 1 --width 1 --density 3
python-escpos text --txt $LNBREAK
python-escpos text --txt "$1"
python-escpos text --txt $LNBREAK
}
DATA=""
for file in "$@"
do
DATA=$(cat $file)
for ln in $DATA
do
COUNTER=0
TEAARRAY=()
for item in $(echo $ln | tr '\|' '\n')
do
TEAARRAY[$COUNTER]="$(echo $item | tr '_' ' ')"
COUNTER=$((COUNTER+1))
done
FORTUNE=$(fortune -sn $PRINTLEN)
echo "From: ${TEAARRAY[0]}, Maker: ${TEAARRAY[1]}"
echo "Tea: ${TEAARRAY[2]}, Type: ${TEAARRAY[3]}"
echo -e "\t$FORTUNE\n"
python-escpos set --align "left" --font "center" --text_type "NORMAL" \
--height 1 --width 2 --density 3
python-escpos text --txt "From: ${TEAARRAY[0]}"
python-escpos text --txt "Maker: ${TEAARRAY[1]}"
python-escpos text --txt "Tea: ${TEAARRAY[2]}"
python-escpos text --txt "Type: ${TEAARRAY[3]}"
fort "$FORTUNE"
python-escpos cut
done
done
setnorms

56
toml_teaprint.py Executable file
View file

@ -0,0 +1,56 @@
#!/bin/python3
import argparse, tomli, subprocess
from escpos.printer import File
p = File("/dev/usb/lp0")
# Garbage params
columns = 42
lnbreak = "-" * columns
# Setup args.
parser = argparse.ArgumentParser()
parser.add_argument('file', help = "Input files", type=argparse.FileType(mode='rb'))
args = parser.parse_args()
def layout(item):
return """Year: {year}
Maker: {factory}
Tea: {style}
Category: {category}
""".format(**item, lnbreak = lnbreak)
# Get fortune
def fort(cols):
out = subprocess.run(["fortune", "-sn", str(cols)], capture_output=True, universal_newlines=True)
out = str(out.stdout).strip("\n")
return out
# Fast reset for printer.
def reset():
p.set(align='left', font='left', text_type="NORMAL", height=1, width=1, density=1)
p.charcode('multilingual')
# Process TOML into dictionary
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"]
}
fortune = fort(columns)
line = layout(tea)
# Start printing
p.set(align='left', font='center', text_type="NORMAL", height=1, width=2, density=3)
p.text(line)
p.set(align='center', font='left', text_type="B", height=1, width=1, density=3)
p.text(lnbreak + "\n")
p.text(fortune + "\n")
p.text(lnbreak + "\n")
p.cut()
reset()

14
xon.py
View file

@ -14,13 +14,13 @@ xon_api = "https://xonotic.lifeisabug.com/endpoint/json"
# Create table
console = Console()
servlist = Table(show_header=True, header_style="bold cyan")
servlist.add_column("", justify="right", min_width=6)
servlist.add_column("Server", justify="left", min_width=72)
servlist.add_column("Mode", justify="center", min_width=6)
servlist.add_column("Map", justify="center", min_width=24)
servlist.add_column("Count", justify="right", min_width=6)
servlist.add_column("IP", justify="left", min_width=24)
servlist = Table(show_header=True, expand=True, header_style="bold cyan")
servlist.add_column("", justify="right", max_width=6)
servlist.add_column("Server", justify="left", ratio=0.1, no_wrap=True)
servlist.add_column("Mode", justify="center", max_width=6)
servlist.add_column("", justify="center", ratio=0.05)
servlist.add_column("", justify="right", max_width=6)
servlist.add_column("IP", justify="left", min_width=22)
# Request json from xon_api
try: