def receipt_printer(settings, transaction): headers = settings.header['lines'] footers = settings.footer['lines'] epson = escpos.Network(settings.ip_address) # Image epson.set(align='center') epson.image(os.path.join(os.path.dirname(__file__), 'test.png')) epson.text('\n\n') # Do header if len(headers): for header in headers: size = int(header['size']) epson.set(align=header['align'], font="a", height=size, width=size) epson.text(header['text'] + '\n') # Then do items for key, item in transaction['items'].iteritems(): epson.set(align='left', font="a", height=1, width=1) epson.text('\n\n') epson.text(align_left(' ' + item['name'], str(item['paid']), 1)) if float(item['discount']) > 0: epson.set(align='left', font="a", height=1, width=1) epson.text( align_left( ' (' + str(item['quantity']) + ' @ ' + str(item['paid']) + ' ea)', 'Discount ' + str(item['discount']) + '- ', 1)) else: epson.set(align='left', font="a", height=1, width=1) epson.text(' (' + str(item['quantity']) + ' @ ' + str(item['paid']) + ' ea)') epson.set(align='left', font="a", height=1, width=1) epson.text('\n\n' + align_left(' Subtotal', str(transaction['subtotal']), 1)) epson.set(align='left', font="a", height=1, width=1) epson.text( align_left(' Tax(' + str(transaction['tax_percent']) + '%)', str(transaction['tax_total']), 1)) epson.set(align='left', font="a", height=2, width=2) epson.text(align_left(' TOTAL', str(transaction['total']), 2)) epson.text('\n\n\n') # Do footer if len(footers): for footer in footers: size = int(footer['size']) epson.set(align=footer['align'], font="a", height=size, width=size) epson.text(footer['text'] + '\n') epson.cut()
def connect(self): try: if self.printer_type == 0: print "Try connect to printer " + self.port self.Epson = printer.Serial(self.port) return True, "Printer Connected to " + self.port if self.printer_type == 1: print "Try connect to printer " + self.ip_address self.Epson = printer.Network(self.ip_address) return True, "Printer Connected to " + self.ip_address except escpos.Error as e: print e return False, e
def goPrintWP(item_id): if request.method == 'GET': url = "https://%s:%s@%s/admin/api/%s" % (API_KEY, PASSWORD, DOMAIN, API_VER) shopify.ShopifyResource.set_site(url) ordx = shopify.Order.find(item_id) kitchen = printer.Network("192.168.51.144") #https://python-escpos.readthedocs.io/en/latest/api/escpos.html #kitchen.set(align="left") #kitchen.text("TEST AUTOMATIC PRINTING \n") kitchen.text("FISHOP " + ordx.name) kitchen.text("\nStatus: " + ordx.financial_status) kitchen.text("\nDate : " + ordx.created_at) kitchen.text("\n: " + ordx.shipping_lines[0].title) kitchen.text("\n\n" + ordx.shipping_address.name) kitchen.text("-" + str(ordx.shipping_address.phone)) kitchen.text("\n" + str(ordx.shipping_address.province)) _addr1 = str(ordx.shipping_address.address1) _addr2 = str(ordx.shipping_address.address2) if _addr1 == 'None': _addr1 = "-" if _addr2 == 'None': _addr2 = "-" #192.168.52.137 kitchen.text("\nAddr: " + _addr1) kitchen.text("\n : " + _addr2) kitchen.text("\n") kitchen.text("-" * 32) kitchen.text("\nQty Price Name") for lin in ordx.line_items: kitchen.text("\n " + str(lin.quantity)) _price = int(float(lin.price)) kitchen.text(" " + format(_price, ",d")) kitchen.text(" " + lin.title) #print("\n") kitchen.text("\n") kitchen.text("-" * 32) _total = int(float(ordx.total_price)) kitchen.text("\nTOTAL: " + format(_total, ",d")) kitchen.text("\n") kitchen.text("\nNote:" + ordx.note) kitchen.text("\n\n\ndfsfsfdf") kitchen.cut() #print("PRINT ORDER:",item_id) return redirect("/", code=302) return index()
def __init__(self): """Setup printer configuration """ from proxypos.proxypos import config # Init printer ptype = config.get('printer.type').lower() settings = config.get('printer.settings') if ptype == 'usb': self.printer = printer.Usb(settings['idVendor'], settings['idProduct']) elif ptype == 'serial': self.printer = printer.Serial(settings['devfile']) elif ptype == 'network': self.printer = printer.Network(settings['host']) # Assign other default values self.printer.pxWidth = settings['pxWidth'] # Set default widht with normal value self.printer.width = self.printer.widthA = settings['WidthA'] self.printer.widthB = settings['WidthB'] # Set correct table character if 'charSet' in settings: self.printer.text(settings['charSet'])
def get_BT_device_list(): devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()] # failure if devices list empty if len(devices) == 0: print("No devices found, try running with sudo") sys.exit(1) # iteratively check device list for BT device print('checking connected devices...') for device in devices: if device.name == TRIGGER_DEVICE: # look for trigger device print(device) device.grab( ) # other apps unable to receive events until device released for event in device.read_loop(): if event.type == evdev.ecodes.EV_KEY: data = evdev.categorize( event) # Save the event temporarily to introspect it if data.keystate == 1: # Down events only print(data.scancode) if data.scancode == 28: p = printer.Network("192.168.1.30") p.image("ec_square.png") p.set( align=u'center', font=u'a', text_type=u'b', ) p.text(datetime.datetime.now().strftime( "%I:%M%p on %B %d, %Y") + "\n") results = sp.current_user_playing_track() result = results['item'] artist = result['artists'][0]['name'] title = result['name'] song = artist + "-" + title p.text(song + "\n") p.cut() if data.scancode == 115: p = printer.Network("192.168.1.30") p.image("ec_square.png") p.set( align=u'center', font=u'a', text_type=u'b', ) p.text(datetime.datetime.now().strftime( "%I:%M%p on %B %d, %Y") + "\n") byMinute = forecast.minutely() p.text(byMinute.summary) p.text("\n") today = datetime.datetime.now() p.set( align=u'left', font=u'b', text_type=u'normal', ) #today_in_history = histopy.load_history(today) #events = histopy.load_events(today_in_history) #random_year = random.choice(list(events)) #event = events[random_year] #p.text(word_wrap('\nOn this day in '+random_year+', '+event+'\n')) locations = [ "HACKNEY TOWN HALL", "MORNING LANE / TRELAWNEY ESTATE", "HACKNEY CENTRAL OVERGROUND" ] for location in locations: print location p.set( align=u'center', font=u'b', text_type=u'b', ) p.text("\n") p.text(location.title() + "\n") this_stop = tfl.searchBusStop(location) this_stop_code = this_stop[location] buses = fetchBusArrivals(this_stop_code) p.set( align=u'center', font=u'b', text_type=u'normal', ) for bus in buses: bus_no = bus[0] bus_destination = bus[1] bus_mins_to_arrival = "in %s min " % ( bus[2]) line1 = "to " + bus_destination if bus[2] > 200: bus_mins_to_arrival = "* " line1 = "Station closed *" p.text(bus_mins_to_arrival) for bus, times in buses.items(): if (times[0] > 120): p.text("Station closed") else: print_times = "" sorted_times = sorted(times) for time in sorted_times: print_times = print_times + str( time) + "," print_times = print_times[:-1] p.text("%s in %s minutes\n" % (bus, print_times)) p.set( align=u'center', font=u'a', text_type=u'normal', ) p.text("\nOur postcode is ") p.set( align=u'center', font=u'a', text_type=u'b', ) p.text("E9 6ND\n") p.set( align=u'center', font=u'a', text_type=u'normal', ) p.text("Mare St Cars: 020 8986 4211\n\n") p.text("Thanks for joining us at Every Cloud") p.cut() p.close()
scope = 'user-read-currently-playing' username = "******" current_song = "" hour = "" token = util.prompt_for_user_token( username, scope, client_id='SPOTIFY APP ID', client_secret='SPOTIFY APP SECRET', redirect_uri='http://localhost:5000/callback') sp = spotipy.Spotify(auth=token) p = printer.Network("PRINTER STATIC IP") TRIGGER_DEVICE = 'AB Shutter3' def get_BT_device_list(): devices = [evdev.InputDevice(fn) for fn in evdev.list_devices()] # failure if devices list empty if len(devices) == 0: print("No devices found, try running with sudo") sys.exit(1) # iteratively check device list for BT device print('checking connected devices...') for device in devices:
#!/usr/bin/python from escpos import printer import forecastio import requests import histopy import datetime import random import math from collections import defaultdict import RPi.GPIO as GPIO p = printer.Network("192.168.1.11") p.image("ec_square.png") p.set( align=u'center', font=u'a', text_type=u'b', ) p.text(datetime.datetime.now().strftime("%I:%M%p on %B %d, %Y") + "\n") p.text("\n")
saleNo = str(row[0]) date = str(row[1]) total = str(row[2]) numItems = str(row[3]) custName = row[4] custAdd = "" if row[5] is not None: custAdd = row[5] custPhone = "" if row[6] is not None: custPhone = row[6] soldBy = row[7] paymentMethod = row[8] #printing p = printer.Network("") ## insert IP #p.close() #p.open() p.image("") ## insert logo p.text("\n" * 2) p.text("Sale no:" + saleNo) p.text(" " * 25 + date + "\n" * 2) p.text("Sold to: " + custName + "\n" * 2) p.text("TEST PRODUCT \n" * 5) p.text("\n") p.text("Total: $" + total + "\n") p.text("Payment method: " + paymentMethod + "\n") p.text("Sold by: " + soldBy + "\n") p.text("\n" * 5) p.cut(mode="PART")
def instance(): socket.socket.connect = mock.Mock() return printer.Network("localhost")
def rprint(self, saleid): p = printer.Network("") ## insert ip # company and customer data p.image("", high_density_vertical=True, high_density_horizontal=True, impl="bitImageRaster", fragment_height=10060, center=True) ##insert logo p.set(u'center') p.text("") ## insert address p.ln() p.text("PHONE FAX") ## insert phone numbers p.ln() p.text("") ## insert email p.ln() p.text("") ## insert website p.ln(count=3) p.set(u'left') p.text("SALE NO.: " + str(saleid)) p.text(" " * (28 - (len(str(saleid))))) p.text(self.date) p.ln(count=3) p.text("SERVED BY: " + self.salesman) p.ln() p.text("SOLD TO: " + self.customer) p.ln(count=2) p.text(("-" * 48) + "\n") # products for item in self.items: p.set(u'left') p.text(item["CODE"]) whitespace = 47 - len(item["CODE"]) - len(item["DESC"]) p.text(" " * whitespace) p.text(item["DESC"] + "\n") p.set(u'right') p.text(item["QTY"] + " @ ") p.text("$" + item["RATE"] + " = ") p.text("$" + item["TOTAL"] + "\n") p.text(("-" * 48) + "\n") p.ln(count=2) # aligning totals subspace = 1 taxspace = 1 totspace = 1 if len(self.total) != len(self.subtotal): subspace += (len(self.total) - len(self.subtotal)) if len(self.taxes) == len(self.subtotal): taxspace = subspace else: taxspace += (len(self.subtotal) - len(self.taxes)) p.set(u'right') p.text("SUBTOTAL:" + " " * subspace + "$" + str(self.subtotal)) p.ln(count=1) p.text("SALES TAX TOTAL:" + " " * taxspace + "$" + str(self.taxes)) p.ln(count=1) p.text("TRANSACTION TOTAL:" + " " * totspace + "$" + str(self.total)) p.ln(count=2) p.text("PAYMENT METHOD: " + self.paymethod) p.ln(count=1) # disclaimer p.set(u'center') p.text('\n' * 3) p.text('') ## insert return policy p.ln(count=4) # barcode saleid = (12 - len(str(saleid))) * "0" + str(saleid) p.barcode(saleid, 'UPC-A', width=5, function_type='A') p.ln(count=3) p.cut(mode="PART") p.close()