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
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()
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 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")