Beispiel #1
0
def print_docx(document: telegram.Document):
    new_path = f'./tmp/{document.file_name.replace(" ", "_")}'

    open(new_path, 'wb').close()
    with open(new_path, 'wb') as f:
        document.get_file().download(out=f)
    try:
        command = f'libreoffice --pt CLP-320-Series {new_path}'

        res = subprocess.run(args=command.split(),
                             check=True,
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE,
                             text=True)
        print(res.stdout)
        print(res.stderr)
    except Exception as e:
        print(e)

    printer_await()
    os.remove(new_path)
Beispiel #2
0
def print_normal_file(document: telegram.Document):
    new_path = f'./tmp/{document.file_name.replace(" ", "_")}'

    open(new_path, 'wb').close()
    with open(new_path, 'wb') as f:
        document.get_file().download(out=f)
    try:
        orientation = 3 if settings[ORIENTATION] is Orientation.portrait else 4
        command = f'lpr -# {settings[COPIES]} ' \
                  f'-o orientaion-requested={orientation} ' \
                  f'-P CLP-320-Series ' \
                  f'{new_path}'

        res = subprocess.run(args=command.split(),
                             check=True,
                             stdout=subprocess.PIPE,
                             text=True)
        print(res)
    except Exception as e:
        print(e)

    printer_await()
    os.remove(new_path)