Command line switches and new functionality

master
José Carlos Cuevas 4 years ago
parent e239da0c13
commit 70cffdeb57

@ -6,7 +6,6 @@ feedparser==5.2.1
idna==2.10
importlib-metadata==1.7.0
Pillow==7.2.0
pkg-resources==0.0.0
pyserial==3.4
python-escpos==2.2.0
pyusb==1.0.2

@ -1,6 +1,7 @@
#! /usr/bin/env python
# python imports
import argparse
import logging
import datetime
import os.path
@ -37,7 +38,7 @@ def initialize():
printer_endpoint = config.get("PRINTER_ENDPOINT") or 0x01
# return Usb(prid1, prid2, printer_interface, printer_endpoint)
return File("/dev/usb/lp2")
return File("/dev/usb/lp0")
def reset_defaults(printer):
@ -144,21 +145,87 @@ def _print_rss_item(item):
printer.text("\n")
def print_text(printer, text):
"""
Prints a text in the smallest form possible
"""
reset_defaults(printer)
# Set the font to a small one and align to
# the left
printer.set(align="left",
text_type="NORMAL",
font="b",
smooth=True)
printer.text("\n")
printer.text(text)
def print_file(printer, file):
"""
Prints a file
"""
reset_defaults(printer)
# Set the font to a small one and align to
# the left
printer.set(align="left",
text_type="NORMAL",
font="b",
smooth=True)
printer.text("\n")
for line in file:
printer.text(line)
file.close()
printer.text("\n\n")
def clear_html(text):
cleanr = re.compile('<.*?>|&([a-z0-9]+|#[0-9]{1,6}|#x[0-9a-f]{1,6});')
cleantext = re.sub(cleanr, '', text)
return cleantext
def create_parser():
"""
Create an argpaser for command line interaction
"""
parser = argparse.ArgumentParser()
parser.add_argument("--weather", default=False)
parser.add_argument("--news", default=False)
parser.add_argument("--text", nargs=1, default=None)
parser.add_argument("--file", default=None, type=open)
return parser
if __name__ == "__main__":
printer = initialize()
print_weather(printer)
printer.text("\n\n")
print_rss(printer, "https://victorhckinthefreeworld.com/feed/")
printer.text("\n\n")
print_rss(printer, "https://pedalibre.org/feed/")
printer.text("\n\n")
print_rss(printer, "https://skyandtelescope.org/observing/sky-at-a-glance/feed/")
printer.text("\n\n")
print_rss(printer, "https://www.space.com/feeds/all", news=2)
printer.text("\n\n")
parser = create_parser()
args = parser.parse_args()
if args.text:
print_text(printer, args.text)
printer.text("\n\n")
if args.file:
print_file(printer, args.file)
printer.text("\n\n")
if args.weather:
print_weather(printer)
printer.text("\n\n")
if args.news:
print_rss(printer, "https://victorhckinthefreeworld.com/feed/")
printer.text("\n\n")
print_rss(printer, "https://pedalibre.org/feed/")
printer.text("\n\n")
print_rss(printer, "https://skyandtelescope.org/observing/sky-at-a-glance/feed/")
printer.text("\n\n")
print_rss(printer, "https://www.space.com/feeds/all", news=2)
printer.text("\n\n")

Loading…
Cancel
Save