Newsboat improvements, python style improvements.
This commit is contained in:
parent
e2b0444543
commit
c895755a00
|
@ -1,32 +1,19 @@
|
|||
#!/bin/bash
|
||||
|
||||
loop() {
|
||||
while true ; do
|
||||
OUTPUT=$(newsboat -x reload)
|
||||
if [ $? == 0 ]
|
||||
then
|
||||
echo $OUTPUT
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
}
|
||||
|
||||
check() {
|
||||
OUTPUT=$(newsboat -x print-unread)
|
||||
if [ $? == 0 ]
|
||||
then
|
||||
echo $OUTPUT | sed 's/ .*/ articles/;s/^/ /'
|
||||
else
|
||||
echo " ..."
|
||||
fi
|
||||
}
|
||||
|
||||
# Newsboat manager for cron and bars
|
||||
case $1 in
|
||||
update|up)
|
||||
loop
|
||||
# Wait for no newsboat, then reload.
|
||||
pidwait -x "newsboat"
|
||||
newsboat -x reload
|
||||
;;
|
||||
fetch|fe)
|
||||
check
|
||||
# Check if newsboat is running. If so, return count.
|
||||
# Else, return padding.
|
||||
if [ -z $(pgrep -x "newsboat") ]; then
|
||||
newsboat -x print-unread | sed 's/ .*/ articles/;s/^/ /'
|
||||
else
|
||||
echo " ..."
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
|
|
@ -1,56 +1,83 @@
|
|||
#!/bin/python3
|
||||
|
||||
import argparse, tomli, subprocess
|
||||
import argparse
|
||||
import tomli
|
||||
import subprocess
|
||||
|
||||
from escpos.printer import File
|
||||
|
||||
p = File("/dev/usb/lp0")
|
||||
p = 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()
|
||||
|
||||
|
||||
def layout(item):
|
||||
return """Year: {year}
|
||||
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)
|
||||
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.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"]
|
||||
'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.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.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()
|
||||
|
|
6
xon.py
6
xon.py
|
@ -49,8 +49,10 @@ for rserv in data["server"]:
|
|||
}
|
||||
|
||||
# Sort by number of players
|
||||
sorted_servers = dict(
|
||||
sorted(unsorted.items(), key=lambda pcount: pcount[1]["num"], reverse=True))
|
||||
sorted_servers = dict(sorted(
|
||||
unsorted.items(),
|
||||
key=lambda pcount: pcount[1]["num"],
|
||||
reverse=True))
|
||||
|
||||
# Fill out table and do operations to colorize the data
|
||||
for server in sorted_servers:
|
||||
|
|
Loading…
Reference in New Issue