diff --git a/config.py b/config.py index 3e59ea0..6279892 100644 --- a/config.py +++ b/config.py @@ -31,6 +31,5 @@ def load_config(): else: with path.open("r") as cfg_file: config = yaml.load(cfg_file.read(), Loader=yaml.FullLoader) - print(config) return config diff --git a/smallprint.py b/smallprint.py index 5dc72c9..ac3d283 100644 --- a/smallprint.py +++ b/smallprint.py @@ -10,7 +10,7 @@ import os.path import sys # 3rd party imports -from escpos.printer import Usb, Dummy, File +from escpos.printer import Usb, File import feedparser import ignition from PIL import Image @@ -28,6 +28,8 @@ logger = logging.getLogger(__name__) config = {} +genqr = False + def initialize(): """ @@ -171,13 +173,21 @@ def print_gemini(printer, link): elif line.startswith("=>"): reset_defaults(printer) - printer.set(align="left", - font="b") - printer.text(line[3:]) - reset_defaults(printer) - lnk = _process_link(link, line[3:]) - printer.text("\n") - printer.qr(lnk, size=6) + if generate_qr: + printer.set(align="left", + font="b") + printer.text(line[3:]) + reset_defaults(printer) + lnk = _process_link(link, line[3:]) + printer.text("\n") + printer.qr(lnk, size=6) + + else: + printer.set(align="left", + font="b", + text_type="U") + printer.text(line) + printer.text("\n") else: printer.set(align="left", @@ -243,8 +253,10 @@ def _print_rss_item(item): printer.text(f"{date}\n\n") printer.text(text) printer.text("\n") - printer.qr(link, size=6) - printer.text("\n") + + if generate_qr: + printer.qr(link, size=6) + printer.text("\n") def print_text(printer, text): @@ -324,12 +336,13 @@ def create_parser(): """ parser = argparse.ArgumentParser() - parser.add_argument("--weather", default=False) - parser.add_argument("--news", default=False) - parser.add_argument("--gemini", default=False) - parser.add_argument("--text", nargs=1, default=None) - parser.add_argument("--file", default=None, type=open) - parser.add_argument("--image", nargs=1, default=None) + parser.add_argument("--weather", default=False, help="Prints the weather in the given city") + parser.add_argument("--news", default=False, help="Loads a RSS or ATOM feed and prints it out") + parser.add_argument("--gemini", default=False, help="Loads a Gemini url and prints it out") + parser.add_argument("--text", nargs=1, default=None, help="Print the given text, use '-' to read from stdin") + parser.add_argument("--file", default=None, type=open, help="Loads a file and sends it to the printer (as text)") + parser.add_argument("--image", nargs=1, default=None, help="Print an image") + parser.add_argument("--genqr", action="store_true", help="Activates the generation of QR codes for links in news and gemini") return parser @@ -340,6 +353,8 @@ if __name__ == "__main__": parser = create_parser() args = parser.parse_args() + generate_qr = args.genqr + if args.text: print_text(printer, args.text[0]) printer.text("\n\n") @@ -354,6 +369,7 @@ if __name__ == "__main__": if args.gemini: print_gemini(printer, args.gemini) + printer.text("\n\n") if args.news: print_rss(printer, args.news)