|
|
|
@ -18,6 +18,7 @@ import re
|
|
|
|
|
import requests
|
|
|
|
|
|
|
|
|
|
from config import load_config, CONFIG_PATH
|
|
|
|
|
from webdav import Client
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Enable logging
|
|
|
|
@ -335,6 +336,36 @@ def print_image(printer, image):
|
|
|
|
|
os.remove("temp.png")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def print_calendar(printer):
|
|
|
|
|
"""
|
|
|
|
|
Connects to a webdav calendar and retrieves
|
|
|
|
|
the events for today
|
|
|
|
|
"""
|
|
|
|
|
c = Client(config)
|
|
|
|
|
events = c.get_todays_events()
|
|
|
|
|
|
|
|
|
|
printer.set(align="center",
|
|
|
|
|
text_type="BU",
|
|
|
|
|
smooth=True)
|
|
|
|
|
printer.text("Today:\n")
|
|
|
|
|
|
|
|
|
|
printer.set(align="left",
|
|
|
|
|
text_type="NORMAL",
|
|
|
|
|
font="b",
|
|
|
|
|
smooth=True)
|
|
|
|
|
|
|
|
|
|
for event in events:
|
|
|
|
|
hour = event[1].hour
|
|
|
|
|
minutes = event[1].minute
|
|
|
|
|
if minutes < 10:
|
|
|
|
|
printer.text(f"{hour}:0{minutes}\n")
|
|
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
printer.text(f"{hour}:{minutes}\n")
|
|
|
|
|
|
|
|
|
|
printer.text(f"{event[0]}\n--\n")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def printing_script(printer):
|
|
|
|
|
"""
|
|
|
|
|
Gets the configuration and parses its script
|
|
|
|
@ -366,6 +397,9 @@ def printing_script(printer):
|
|
|
|
|
if key == 'TEXT':
|
|
|
|
|
print_text(printer, value)
|
|
|
|
|
|
|
|
|
|
if key == 'CALENDAR':
|
|
|
|
|
print_text(printer)
|
|
|
|
|
|
|
|
|
|
printer.set(align="center",
|
|
|
|
|
text_type="NORMAL",
|
|
|
|
|
font="b",
|
|
|
|
@ -391,6 +425,7 @@ def create_parser():
|
|
|
|
|
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("--calendar", action="store_true", help="Print configured calendar events for today")
|
|
|
|
|
parser.add_argument("--genqr", action="store_true", help="Activates the generation of QR codes for links in news and gemini")
|
|
|
|
|
|
|
|
|
|
return parser
|
|
|
|
@ -435,6 +470,11 @@ if __name__ == "__main__":
|
|
|
|
|
print_image(printer, args.image[0])
|
|
|
|
|
printer.text("\n\n")
|
|
|
|
|
|
|
|
|
|
if args.calendar:
|
|
|
|
|
ops_called += 1
|
|
|
|
|
print_calendar(printer)
|
|
|
|
|
printer.text("\n\n")
|
|
|
|
|
|
|
|
|
|
# In case we get called (almost) empty
|
|
|
|
|
if ops_called == 0:
|
|
|
|
|
# Try to parse a config script
|
|
|
|
|