コード例 #1
0
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()
コード例 #2
0
ファイル: bragi.py プロジェクト: ArwinV/BragiTelegramBot
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()