Last active
April 10, 2024 14:57
-
-
Save wadefletch/7df0e190871f7891b18efcd1f2415c92 to your computer and use it in GitHub Desktop.
Print from Todoist API to USB Thermal Printer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import todoist | |
from escpos import printer | |
therm = printer.Usb(0x0416, 0x5011) # connect to printer | |
api = todoist.TodoistAPI('79d4d663cc5011ab78cd7004e26a1a060572c823') # connect to todoist | |
api.sync() # get new data from todoist | |
therm.image('name.png') # print header image | |
therm.text('\n') # add a blank line | |
therm.set(font='B') # use smaller 'B' font | |
for item in api.state['items']: # get all items from todoist | |
if item['checked'] == 0: # filter out completed items | |
line = '[ ] '+item['content'] # add checkbox to begining of line | |
if len(line) > 42: # if line is wider than reciept, | |
line = line[:42] + ' '*4 + line[42:] # add 4 spaces to wrap to next line | |
therm.text(line+'\n') # print line | |
therm.text('\n'*4) # print blank lines so there is a margin to tear off |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment