class bonprinter: def __init__(self, logger, config, printq): self.logger = logger self.cf = config self.printq = printq #self.p = None self.p = Serial(devfile='/dev/ttyUSB1', baudrate=38400, bytesize=8, parity='N', stopbits=1, timeout=1.00, dsrdtr=False, profile="TM-T88II") self.pprint = printerpreter(self.p) # pretty printer def brrr(self, context): for item in self.printq: if item['printed'] is False: context.bot.send_message(chat_id=item['id'], text=printing_text) self.printq.update(tdbop.set("printed", True), Query().date == item['date']) # mark as printed so errors dont result in infinite loops if item['text'] is not None: self.pprint.printbon(item['text']) if item['image'] is not None: self.p.image(item['image'], impl='bitImageRaster') self.p.text("\n------------------------------------------\n") if self.cf['auto_cut'] is True: self.p.cut(mode='FULL', feed=True, lines=4) if item['image'] is not None: sleep(2) # timeout so printer can cool down
class Imprimir: def __init__(self, porta_serial): self.p = Serial(porta_serial) self.p.charcode("MULTILINGUAL") self.nome_serial = porta_serial def imprimir_texto(self, texto): self.p.text(str(texto)) self.p.cut() def imprimir_imagem(self, imagem): self.p.image(str(imagem)) self.p.cut() def imprimir_qr_code(self, texto): self.p.qr(str(texto)) self.p.cut() def retornar_impressora(self): return str(self.nome_serial)
def print_list(list): p = Serial(devfile="/dev/ttyUSB0", baudrate=38400, bytesize=8, parity='N', stopbits=1, timeout=1.00, dsrdtr=True) p.set('center', 'B', 'B', 2, 2) p.text(f"{list.name}\n") p.set('left', 'A', 'normal', 1, 1) for item in list.items: p.text(f"[ ] {item.name}\n") date = datetime.now().strftime("%Y-%m-%d %H:%M:%S") p.set('right', 'B', 'normal', 1, 1) p.text(f"\nas of {date}\n") p.cut()
def main(): """Starting point""" # Printer object global p p = Serial(devfile='/dev/receipt_printer', baudrate=115200, bytesize=8, parity='N', stopbits=1, timeout=1.00, dsrdtr=True) # Printer settings p.set(align='center') # Print started message p.text("Bragi started!") p.cut() # Load saves dict global data try: with open("saves.json") as save_file: data = json.load(save_file) except FileNotFoundError: logging.info("saves.json file not found. Creating the file.") data = {} data['total_prints'] = 0 data['text_prints'] = 0 data['image_prints'] = 0 data['contact_prints'] = 0 data['poll_prints'] = 0 data['location_prints'] = 0 data['users'] = [] data['last_user_id'] = 0 try: with open("admin_id.txt") as admin_file: admin_id = admin_file.read().strip() except FileNotFoundError: logging.error( "No admin_id file found. Add your user id in a file called admin_id.txt in the same directory as the bot." ) return data['admin_id'] = int(admin_id) with open('saves.json', 'w') as save_file: json.dump(data, save_file) # Start the bot TOKEN = None try: with open("token.txt") as f: TOKEN = f.read().strip() except FileNotFoundError: logging.error( "No token file found. Add your token in a file called token.txt in the same directory as the bot." ) return updater = Updater(TOKEN) dispatcher = updater.dispatcher # Handle commands dispatcher.add_handler(CommandHandler("start", start)) dispatcher.add_handler(CommandHandler("help", help_command)) dispatcher.add_handler(CommandHandler("stats", stats_command)) dispatcher.add_handler(CommandHandler("listusers", listusers_command)) dispatcher.add_handler( CommandHandler("givepermission", givepermission_command)) dispatcher.add_handler( CommandHandler("removepermission", removepermission_command)) dispatcher.add_handler(CommandHandler("anonymous", anonymous_command)) # Handle all the message types! I might be able to OR some lines, but this also works dispatcher.add_handler( MessageHandler(Filters.text & ~Filters.command, print_text)) dispatcher.add_handler(MessageHandler(Filters.photo, print_photo)) dispatcher.add_handler(MessageHandler(Filters.document.image, print_photo)) dispatcher.add_handler(MessageHandler(Filters.audio, print_audio)) dispatcher.add_handler(MessageHandler(Filters.voice, print_audio)) dispatcher.add_handler(MessageHandler(Filters.contact, print_contact)) dispatcher.add_handler( MessageHandler( Filters.document & ~Filters.document.image & ~Filters.document.video, print_document)) dispatcher.add_handler(MessageHandler(Filters.location, print_location)) dispatcher.add_handler(MessageHandler(Filters.poll, print_poll)) dispatcher.add_handler(MessageHandler(Filters.sticker, print_photo)) dispatcher.add_handler(MessageHandler(Filters.video, print_video)) dispatcher.add_handler(MessageHandler(Filters.document.video, print_video)) # Start polling updater.start_polling() updater.idle()
docket_meta_details() if (random.random() < 0.01): print("MAKE EMPTY ITEM INFO docket") make_empty_item_info_docket() elif (random.random() <0.01): print("EDGE CASE docket") make_edge_case_docket() elif (random.random() < 0.01): print("MAKE EMPTY docket") make_empty_docket() elif (random.random() < 0.01): # send a call away docket print("CALL AWAY docket") make_call_away_docket() elif (random.random() < 0.99): # make a standard docket print("STANDARD docket") make_standard_docket() else: # make a solely dessert docket print("DESSERT docket") make_dessert_docket() p.text("\n\n") p.text("-------------------------------\n") p.cut() print("should have a docket printed") print("finished. all " + str(num_of_dockets) + " dockets sent")
area = (0, STRIP_WIDTH * i, img_w, STRIP_WIDTH * (i + 1)) strips[i] = image.crop(area) if img_h % STRIP_WIDTH != 0: strips[-1] = strips[-1].crop((0, 0, img_w, img_h % STRIP_WIDTH)) # Dump strips into a temporary directory if not os.path.exists('.temp'): os.mkdir('.temp') for i in range(num_strips): strips[i].save(os.path.join('.temp', "strip{0:03}.png".format(i))) # Do the printing p = Serial(devfile='COM5', baudrate=9600, parity='N', stopbits=1, timeout=1.00, dsrdtr=True) p.text("\033@") # Reset p.text("\033C\20") # Set sheet eject length p.text("\0331") # Select 1/8-inch line spacing p.text("\033$\000\000") # Set left margin p.text("\033a\001") # Center align for i in range(num_strips): p.image(os.path.join('.temp', "strip{0:03}.png".format(i))) p.text("\033a\000") # Left align #p.cut()
from escpos.printer import Serial p = Serial(devfile='COM5', baudrate=9600, parity='N', stopbits=1, timeout=1.00, dsrdtr=True) p.text("\033@") # Reset p.text("\033C\100") # Set sheet eject length p.text("\0331") # Select 1/8-inch line spacing p.text("\033$\000\030") # Set left margin p.text("\033a\000") # Left align p.text("See back of receipt for your chance\n") p.text("to win $1000 ID #:7N77MVS1VUY\n") p.text("\033a\001") # Center align p.image("C:\\Users\\Alexander\\Desktop\\download.jpg") p.text("978-851-6265 Mgr:BETH WATERHOUSE\n") p.text("333 MAIN ST\n") p.text("TEWKSBURY MA 01876\n") p.text("\033a\000") # Left align p.text("ST# 02222 OP# 009056 TE# 56 TR# 00079\n") p.text("PRNCS DIA RING 00128182447 F 52000.00 T\n") p.text("PRNCS DIA RING 00128182447 F 52000.00 T\n") p.text("PRNCS DIA RING 00128182447 F 52000.00 T\n") p.text("PRNCS DIA RING 00128182447 F 52000.00 T\n")