Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from __future__ import print_function
from datetime import datetime
import calendar
import urllib
import json
import time
import os
from escpos.printer import Usb
""" Setting up the main pathing """
this_dir, this_filename = os.path.split(__file__)
GRAPHICS_PATH = os.path.join(this_dir, "graphics/climacons/")
# Adapt to your needs
printer = Usb(0x0416, 0x5011, profile="POS-5890")
# You can get your API Key on www.darksky.net and register a dev account.
# Technically you can use any other weather service, of course :)
API_KEY = "YOUR API KEY"
LAT = "22.345490" # Your Location
LONG = "114.189945" # Your Location
def forecast_icon(idx):
icon = data['daily']['data'][idx]['icon']
image = GRAPHICS_PATH + icon + ".png"
return image
# Dumps one forecast line to the printer
def update_printer():
"""Update the printer."""
global PRINTER # pylint: disable=global-statement
try:
if len(config.PRINTER_ADDR.split()) == 2:
vid, mid = config.PRINTER_ADDR.split()
try:
PRINTER = Usb(int(vid, 16), int(mid, 16))
except ValueError:
pass
except USBNotFoundError:
PRINTER = None
from escpos.printer import Usb
def usage():
print("usage: qr_code.py <content>")
if __name__ == '__main__':
if len(sys.argv) != 2:
usage()
sys.exit(1)
content = sys.argv[1]
# Adapt to your needs
p = Usb(0x0416, 0x5011, profile="POS-5890")
p.qr(content, center=True)
</content>
def open_cashbox():
from proxypos.proxypos import config
# Init printer
ptype = config.get('printer.type').lower()
settings = config.get('printer.settings')
idVendor = settings['idVendor']
idProduct = settings['idProduct']
if ptype == 'usb':
with printer.Usb(idVendor, idProduct) as device:
device.cashdraw(2)
elif ptype == 'serial':
# TODO:
printer.Serial(settings['devfile'])
elif ptype == 'network':
# TODO:
printer.Network(settings['host'])
def is_alive():
from proxypos.proxypos import config
# Init printer
ptype = config.get('printer.type').lower()
settings = config.get('printer.settings')
idVendor = settings['idVendor']
idProduct = settings['idProduct']
if ptype == 'usb':
with printer.Usb(idVendor, idProduct) as device:
pass
elif ptype == 'serial':
# TODO:
printer.Serial(settings['devfile'])
elif ptype == 'network':
# TODO:
printer.Network(settings['host'])
def print_receipt(receipt):
""" Function used for print the receipt
"""
# Import configuration handler
from proxypos.proxypos import config
from proxypos.proxypos import tmphandler
# Init printer
ptype = config.get('printer.type').lower()
settings = config.get('printer.settings')
idVendor = settings['idVendor']
idProduct = settings['idProduct']
if ptype == 'usb':
with printer.Usb(idVendor, idProduct) as device:
# Assign other default values
device.pxWidth = settings['pxWidth']
# Set default widht with normal value
device.width = device.widthA = settings['WidthA']
device.widthB = settings['WidthB']
# Set correct table character
if 'charSet' in settings:
device.text(settings['charSet'])
template = config.get('receipt.template')
# Render and print receipt
tmphandler.print_receipt(device, template, receipt)
elif ptype == 'serial':
# TODO:
printer.Serial(settings['devfile'])
elif ptype == 'network':
# TODO:
def assign(v, p, in_ep, out_ep):
try:
printer = getp.Usb(v, p, 0, in_ep, out_ep)
printer.text("\n")
return printer
except Exception:
return None
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals
from escpos.printer import Usb
# Adapt to your needs
p = Usb(0x0416, 0x5011, profile='POS-5890')
# Print software and then hardware barcode with the same content
p.soft_barcode('code39', '123456')
p.text('\n')
p.text('\n')
p.barcode('123456', 'CODE39')
def connectToPrinter():
try:
p = Usb(0x0416, 0x5011, in_ep=81, out_ep=3)
except USBNotFoundError:
p = None
print("Printer not connected")
return p