class Printr: def __init__(self, bot, config): self.bot = bot self.config = config self.printer = self.config.get("printer") self.p = None @onload def onload(self): self.p = Network(self.printer) print("printer loaded") @unload def unload(self): self.p = None @command("print") def printr(self, msg): self.p.text(msg.text) self.p.cut() return msg.reply(text="Printed!")
def thermalPrint(self): "Prints the pwd on the thermal printer at the specified ip" if self.printerIp: p = Network(self.printerIp) p.set(align='center', text_type='bold', width=2, height=2) p.text("fZone Guest WiFI\n\n") p.set() p.text('\tDate:\t' + datetime.datetime.now().strftime("%I:%M%p on %B %d, %Y") + '\n') p.text('\tSSID:\t' + self.radioSSID + '\n') p.text('\tPwd:\t' + self.pwd + '\n') p.text('\n') p.set(align='center') p.qr('WIFI:T:WPA;S:' + self.radioSSID + ';P:' + self.pwd + ';;', size=6, native=False) p.text('Scan me to login!') p.cut() pass
class Printer: printer = None def __init__(self, ip): self.printer = Network(ip) def Test(self): return True def Print(self, text, convertesc, cutprint, selfont): if self.ConvertBool(convertesc): text = text.replace("\\n", "\n") text = text.replace("\\t", "\t") text = text.replace("\\\\", chr(92)) # text = text.replace("\\", "***") self.printer.set(font=selfont) self.printer.text(text) self.printer.set(font='a') if self.ConvertBool(cutprint): self.printer.cut() def PrintBoxTag(self, caseNumbers, Organisation, inDate, outDate, Contents, Serials): img = qrcode.make("ID" + str(caseNumbers), box_size=8) img.save("out.png") self.printer.set(align=u'center', font='a') self.printer.text("Hospitality Technology\n") self.printer.text("Hardware Department\n") self.printer.image("out.png") self.printer.set(align=u'left') caseNumberString = "" for caseNo in caseNumbers: caseNumberString += " " + caseNo + "\n" contentString = "" for hardware in Contents: contentString += " " + hardware + "\n" serialString = "" for serial in Serials: serialString += " " + serial + "\n" self.printer.text("Property : " + Organisation + "\n") self.printer.text("Received Date : " + inDate + "\n") self.printer.text("Released Date : " + outDate + "\n") self.printer.text("Case No :\n") self.printer.text(caseNumberString + "\n") self.printer.text("Contents :\n") self.printer.text(contentString + "\n") self.printer.text("Serials :\n") self.printer.text(serialString + "\n") self.printer.cut() def StressTest(self, line_count): chararr = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0" ] for y in range(line_count): string = "" for x in range(42): string += chararr[randrange(0, len(chararr) - 1)] self.printer.text(string) self.printer.text("\n\n") self.printer.cut() def AdvancedStressTest(self, line_count, infont, alphabet, numbers, specialChars, CutAfterPrint): alphabet = self.ConvertBool(alphabet) numbers = self.ConvertBool(numbers) specialChars = self.ConvertBool(specialChars) CutAfterPrint = self.ConvertBool(CutAfterPrint) finalArray = [] alphabetArray = [ "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" ] numberArray = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"] specialCharsArray = [ "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "-", "=", "+", "\\", "/", "<", ">", ".", ",", '"', "'", ";", ":", "[", "]", "|" ] if numbers: finalArray.extend(numberArray) if alphabet: finalArray.extend(alphabetArray) if specialChars: finalArray.extend(specialCharsArray) self.printer.set(font=infont) for y in range(int(line_count)): string = "" for x in range(42): string += choice(finalArray) self.printer.text(string) if CutAfterPrint: self.printer.text("\n\n") self.printer.cut() self.printer.set(font='a') def ConvertBool(self, instr): if (instr.__eq__("false")): return False return True
def start(): global REDISIP global KEY global PRINTERIP cache = redis.StrictRedis(REDISIP,6379) key = KEY message = cache.get(key) dict = eval(message) print dict #init push printer character if dict.get('orderType') == 1: Big = dict.get('data') Bigstr = str(Big) Bigdict = eval(Bigstr) title = json.dumps(Bigdict.get('storeName'),encoding='UTF-8',ensure_ascii=False) titlefull = title.replace("\"","") orderId = Bigdict.get('orderId') machineId = Bigdict.get('machineId') cashier = Bigdict.get('cashier') orderTime = Bigdict.get('orderTime') takefoodNum = Bigdict.get('takefoodNum') #取餐号 kindchagne = json.dumps(Bigdict.get('kind'),encoding='UTF-8',ensure_ascii=False) kind = kindchagne.replace("\"","") #堂食 / 外带 try: print "init printer" p = Network(PRINTERIP,timeout=10000) p.set(align='center',font='a',text_type='normal',height=1,width=1,invert=False, smooth=False,flip=False) p.text(u"欢迎光临真功夫[%s]\n\n".encode('gbk') % titlefull) p.set(align='center',font='B',text_type='B',height=2,width=2,invert=False, smooth=False,flip=False) p.text(u"取货单\n\n".encode('gbk')) p.set(align='center',font='a',text_type='normal',height=1,width=1,invert=False, smooth=False,flip=False) p.text(u"单号:[%s]\t 机号: [%s]\n 收银员: [%s]\n ".encode('gbk') % (orderId,machineId,cashier)) p.text(u"打单时间: [%s]\n\n".encode('gbk') % orderTime) p.set(align='center',font='B',text_type='B',height=2,width=2,invert=False, smooth=False,flip=False) p.text(u"取餐号: %s\n\n".encode('gbk') % (takefoodNum)) p.set(align='center',font='a',text_type='normal',height=1,width=1,invert=False, smooth=False,flip=False) p.text(u"[%s]合计 Total\n".encode('gbk') % (kind)) p.set(align='left',font='a',text_type='normal',height=1,width=1,density=8,invert=False, smooth=False,flip=False) p.text(u"数量\t\t产品名称\r\n".encode('gbk')) prodList = Bigdict.get('prodList') for prodListdict in prodList: foodnum = prodListdict.get('num') #print foodnum foodnamechagne = json.dumps(prodListdict.get('name'),encoding='UTF-8',ensure_ascii=False) foodname = foodnamechagne.replace("\"","") #print foodname p.text(u"%s\t%s\n".encode('gbk') % (foodnum,foodname)) p.cut() except Exception as e: print ("connect printer %s") % (e) print ("please look at the bus about printer_kitchen alive")
def pos_print(order=None): if order is None: order = [] try: epson = Network("192.168.1.100") epson.image("/home/sysop/pos/rosie.png") bar = '0000' price = 0 for m in order: epson.set(height=2, width=2, align='center') epson.text('Your PIN\n') epson.set(font='a', height=3, width=3, align='center') epson.text(str(m[3]) + '\n') bar = str(m[3]) epson.set(font='a', height=2, width=2, align='left', text_type='u2') epson.text(' Order \n') epson.set(text_type='normal') epson.text(str(m[0])) if int(m[0]) > 1: epson.text(' Cups of Donuts') price = int(m[0]) * 4.76 epson.text(' $' + str(price) + '\n') price = int(m[0]) * 4.7619 else: epson.text(' Cup of Donuts') epson.text(' $4.76\n') price = 4.7619 n = str(m[1]) if int(n[0]) > 1: p = int(n[0]) - 1 epson.text(str(p) + ' ') epson.text('Mountain Dew') p2 = p * 1.9047 p = p * 1.90 price = price + p2 epson.text(' $' + str(p) + '0\n') if int(n[1]) > 0: epson.text(n[1] + ' ') epson.text('Root Beer') p = int(n[1]) * 1.90 p2 = int(n[1]) * 1.9047 price = price + p2 epson.text(' $' + str(p) + '0\n') if int(n[2]) > 0: epson.text(n[2] + ' ') epson.text('Pepsi') p = int(n[1]) * 1.90 p2 = int(n[1]) * 1.9047 price = price + p2 epson.text(' $' + str(p) + '0\n') if int(n[3]) > 0: epson.text(n[3] + ' ') epson.text('7 Up') p = int(n[1]) * 1.90 p2 = int(n[1]) * 1.9047 price = price + p2 epson.text(' $' + str(p) + '0\n') gst = price * .05 nice_gst = math.ceil(gst * 100) / 100 epson.text(' GST: $' + str(nice_gst) + '\n') print(nice_gst) price = price + gst tot = math.ceil(price * 100) / 100 epson.text(' Total: $' + str(tot) + '0\n') print(tot) epson.text('\n\n') epson.set(font='a', height=2, width=2, align='center') epson.text('THANK YOU\n') epson.set(font='a', height=1, width=1, align='center') epson.barcode(bar, 'CODE128', function_type="B") epson.cut() except Exception as ex: print(ex)
def print_ticket(trx_data, gate): try: p = Network(gate['printer_ip_address']) except Exception as e: logging.error(gate['name'] + ' : Failed to print ticket ' + trx_data['barcode_number'] + ' ' + str(e)) send_notification( gate, 'Pengunjung di ' + gate['name'] + ' gagal print tiket. Informasikan nomor barcode kepada pengunjung. ' + trx_data['barcode_number']) return try: p.set(align='center') p.text("TIKET PARKIR\n") p.set(height=2, align='center') p.text(LOCATION['name'] + "\n\n") p.set(align='left') p.text('GATE'.ljust(10) + ' : ' + gate['name'] + "/" + gate['vehicle_type'] + "\n") p.text('TANGGAL'.ljust(10) + ' : ' + datetime.datetime.strptime( trx_data['time_in'][:10], '%Y-%m-%d').strftime('%d %b %Y') + "\n") p.text('JAM'.ljust(10) + ' : ' + trx_data['time_in'][11:] + "\n\n") p.set(align='center') p.barcode(trx_data['barcode_number'], 'CODE39', function_type='A', height=100, width=4, pos='BELOW', align_ct=True) p.text("\n") p.text(LOCATION['additional_info_ticket']) p.cut() except Exception as e: logging.error(gate['name'] + ' : Failed to print ticket ' + trx_data['barcode_number'] + ' ' + str(e)) send_notification( gate, 'Pengunjung di ' + gate['name'] + ' gagal print tiket. Informasikan nomor barcode kepada pengunjung. ' + trx_data['barcode_number']) return logging.info(gate['name'] + ' : Ticket printed ' + trx_data['barcode_number'])
def print_ticket_network(data): try: p = Network(GATE['printer_ip_address']) except Exception as e: logging.error('Failed to print ticket ' + data['nomor_barcode'] + ' ' + str(e)) send_notification( 'Pengunjung di ' + GATE['nama'] + ' gagal print tiket. Informasikan nomor barcode kepada pengunjung. ' + data['nomor_barcode']) return try: p.set(align='center') p.text("TIKET PARKIR\n") p.set(height=2, align='center') p.text(SETTING['nama_lokasi'] + "\n\n") p.set(align='left') p.text('TANGGAL : ' + datetime.datetime.strptime( data['time_in'][:10], '%Y-%m-%d').strftime('%d %b %Y') + "\n") p.text('JAM : ' + data['time_in'][11:] + "\n\n") p.set(align='center') p.barcode(data['nomor_barcode'], 'CODE39', function_type='A', height=100, width=4, pos='BELOW', align_ct=True) p.text("\n") p.text(SETTING['info_tambahan_tiket']) p.cut() except Exception as e: logging.error('Failed to print ticket ' + data['nomor_barcode'] + ' ' + str(e)) send_notification( 'Pengunjung di ' + GATE['nama'] + ' gagal print tiket. Informasikan nomor barcode kepada pengunjung. ' + data['nomor_barcode']) return logging.info('Ticket printed ' + data['nomor_barcode'])
from escpos.printer import Network kitchen = Network("192.168.88.195") #Printer IP Address kitchen.text("Hello World\n") kitchen.barcode('1324354657687', 'EAN13', 64, 2, '', '') kitchen.cut()
def perform_create(self, serializer): lateness = serializer.save() printing = self.request.query_params.get('print', None) lateness_settings = get_settings() lateness_count = self.get_queryset().filter( student=lateness.student, justified=False, ).count() if lateness_settings.printer and printing: try: printer = Network(lateness_settings.printer) if not settings.DEBUG else Dummy() printer.charcode('USA') printer.set(align='CENTER', text_type='B') printer.text('RETARD\n') printer.set(align='LEFT') absence_dt = lateness.datetime_creation.astimezone(timezone.get_default_timezone()) count_or_justified = "Retard justifié" if lateness.justified else "Nombre de retards: " if not lateness.justified: count_or_justified += "%i" % lateness_count printer.text('\n%s %s\n%s\n%s\n%s\nBonne journée !' % ( unidecode(lateness.student.last_name), unidecode(lateness.student.first_name), lateness.student.classe.compact_str, absence_dt.strftime("%H:%M - %d/%m/%Y"), count_or_justified )) if settings.DEBUG: print(printer.output) printer.cut() printer.close() except OSError: pass for trigger in SanctionTriggerModel.objects.filter( teaching=lateness.student.teaching, year__year=lateness.student.classe.year ): count_first = trigger.lateness_count_trigger_first count_trigger = trigger.lateness_count_trigger if lateness_count < count_first or ( lateness_count > count_first and (lateness_count - count_first) % count_trigger != 0 ): continue lateness.has_sanction = True if trigger.only_warn: lateness.save() continue from dossier_eleve.models import CasEleve, SanctionDecisionDisciplinaire sanction = SanctionDecisionDisciplinaire.objects.get(id=trigger.sanction_id) today = datetime.datetime.today() day_shift = 6 + trigger.next_week_day day = today + datetime.timedelta(days=(day_shift - today.isoweekday()) % (6 + trigger.delay) + 1) day.replace(hour=trigger.sanction_time.hour, minute=trigger.sanction_time.minute) cas = CasEleve.objects.create( matricule=lateness.student, name=lateness.student.display, demandeur=self.request.user.get_full_name(), sanction_decision=sanction, explication_commentaire="Sanction pour cause de retard.", sanction_faite=False, datetime_sanction=day, created_by=self.request.user ) cas.visible_by_groups.set(Group.objects.all()) lateness.sanction_id = cas.id lateness.save() if lateness_settings.notify_responsible: responsibles = get_resp_emails(lateness.student) context = {"lateness": lateness, "lateness_count": lateness_count} send_email( responsibles, "[Retard]%s %s %s" % ( "[Sanction]" if lateness.has_sanction else "", lateness.student.fullname, lateness.student.classe.compact_str ), "lateness/lateness_email.html", context=context )
# -*- coding: cp1254 -*- from escpos.printer import Network p = Network("192.168.2.223") p.image('./images/bishop.png') p.text("MUTFAK\n") p.text(chr(27)) p.text(chr(45)) p.text(chr(50)) p.text(u'DONDURUCU\n') p.text(chr(27)) p.text(chr(33)) p.text(chr(17)) p.text('NEN 2016 \n') p.barcode("3057", "CODE39",80,3,"BELOW", "A") p.text('\n') p.barcode("3058", "CODE39",80,3) p.cut()
if printer: if interface == 'tcp': print 'Using TCP interface', host, tcpport Epson = Network(host=host, port=tcpport, timeout=60) time.sleep(2) # wait for network else: print 'Using serial interface', devfile, baud Epson = Serial(devfile=port, baudrate=baud, dsrdtr=True) ret = '\r\n' else: ret = '\n' Epson.image('rulemart.gif', impl='bitImageColumn') Epson.set(font='a') Epson.text('Rule : ' + str(rulenum) + '\n') Epson.text('Lines : ' + str(linesperpage) + '\n') Epson.text(datetime.datetime.now().strftime('Date : %Y/%m/%d %H:%M:%S\n')) output('\x1b\x21\x01', lf=False) # font 'b', 56 chars wide output('\x1b\x33\x20', lf=False) # line spacing output(ret * 3, lf=False) rule30(rule=rulenum) output(ret * 3, lf=False) Epson.barcode(code=datetime.datetime.now().strftime("%Y%m%d%H%M%S"), bc='CODE93', function_type='B') output(ret * 2, lf=False) Epson.set(align='center', font='a') Epson.text('Thank you! Please rule again.') Epson.set(align='left') output(ret * 8, lf=True)