def main(): """entry point for command line users""" parser = argparse.ArgumentParser() parser.add_argument("data", help="Data, that should be encoded") parser.add_argument("output", help="File to store the barcode") parser.add_argument("-H", "--height", default=100, type=int, help="height of generated picture in pixel, default: 100") parser.add_argument("-T", "--thickness", default=3, type=int, help="width of a bar with weight=1 in pixel, default: 3") parser.add_argument("-q", "--no_quiet", action="store_false", default=True, help="Do not include the quiet zone " "before and after the code in the picture") args = parser.parse_args() ftype = splitext(args.output)[1] suptypes = ".bmp .dib .gif .im .jpg .jpe .jpeg .pcx .png .pbm " \ ".pgm .ppm .tif .tiff .xbm .xpm .svg".split() if ftype == ".svg": print("Barcode '%s' created" % args.data) with open(args.output, "w") as f: f.write(code128.svg(args.data, args.height, args.thickness, args.no_quiet)) print("Barcode successfully saved as", args.output) elif ftype in suptypes: img = code128.image(args.data, args.height, args.thickness, args.no_quiet) print("Barcode '%s' created" % args.data) img.save(args.output) print("Barcode successfully saved as", args.output) else: print("Type '%s' is not supportet, use one of these: %s" % (ftype, " ".join(suptypes)) )
def pdf_invoice_creator(self, template_html, output_file_name): self.validate_input() if self.errors: print("\n".join(self.errors)) return with open(os.path.abspath(template_html)) as html_file: parsed_page = BeautifulSoup(html_file, "lxml") self.total_calculate() for target in self.targets: for item in parsed_page.findAll(id=target): if type(self.__dict__[target]) == float: item.string = format(self.__dict__[target], '.2f') elif type(self.__dict__[target]) == datetime.datetime: item.string = str(self.__dict__[target].strftime('%d.%m.%Y')) else: item.string = str(self.__dict__[target]) for item in range(len(self.products)): for value in self.products[item]: src = "{a}_{d}".format(a=item+1, d=value) for html_item in parsed_page.findAll(id=src): if type(self.products[item-1][value]) == float: html_item.string = format(self.products[item-1][value], '.2f') else: html_item.string = str(self.products[item-1][value]) code = BeautifulSoup(code128.svg(self.code_creator()), 'lxml') code.find('svg')['height'] = "40" code.find('svg')['width'] = "528" code.find('svg')['viewbox'] = "0 0 1058 50" code.find('svg')['preserveAspectRatio'] = "xMinYMin meet" parsed_page.find(id='barcode').append(code) self.pdf_file = pdfkit.from_string(str(parsed_page), False, options=config.PDFKIT_CONFIG) with open(output_file_name, 'wb') as newfile: newfile.write(self.pdf_file) return True
# Encode first three words in a barcode # Encode next two words in a QR code # Encode last two words in ASCII Hex import code128 import os import pyqrcode s="the key for number nineteen is humanhorse" alphabet="abcdefghijklmnopqrstuvwxyz " scramble="czxkpytafnuvdhljmioqwbregs " sub_dict=dict(zip(alphabet,scramble)) cipherlist=[sub_dict[c] for c in s] ciphertext=''.join(str(c) for c in cipherlist) words=ciphertext.split() barcodestr=words[0]+" "+words[1]+" "+words[2] qrcodestr=words[3]+" "+words[4] asciistr=words[5]+" "+words[6] with open("19a_final.svg", "w") as f: f.write(code128.svg(barcodestr)) f.close() estring=pyqrcode.create(qrcodestr) estring.svg('19b_final.svg',scale=8) m=''.join(hex(ord(n))[2:].ljust(3,' ') for n in asciistr) with open("19c_final.txt","w") as f: f.write(m+"\n") f.close()
# -*- coding: utf-8 -*- # @Time : 2019/7/23 16:46 # @Author : Yo # @Email : [email protected] # @File : code128demo.py # @Software: PyCharm # @models: .. # @function: ... # @Git: https://gitee.com/m7n9/PyCharm.git # @Edit: yo import code128 code128.image("CUKe3DGg").save("Hello World.png") # with PIL present # with open("Hello World.svg", "w") as f: f.write(code128.svg("Hello World"))
import barcode import os from itertools import cycle s='the key for number twelve is shinymetal in lowercase' import code128 with open("12a_final.svg", "w") as f: f.write(code128.svg("key=WOODEN")) f.close() alpha='ABCDEFGHIJKLMNOPQRSTUVWXYZ' string=s.upper().replace(' ','') plaintext=string.upper().replace(' ','') key='WOODEN' cycledkey=cycle(key) ciphertext=''.join(alpha[(alpha.index(next(cycledkey))+alpha.index(plaintext[i])) % 26] for i in range(len(plaintext))) f=open('12b_final.txt','w') f.write(ciphertext+"\n") f.close()
<!DOCTYPE svg PUBLIC '-//W3C//DTD SVG 1.1//EN' 'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'> <svg height="29.000mm" version="1.1" width="90.300mm" xmlns="http://www.w3.org/2000/svg"> <g transform="translate(-10,0) scale(0.7, 1.2)"> {bar} </g> <g transform="translate(215,15) scale(0.35,0.35)"> {logo} </g> <g> <text x="255" y="85" style="fill:black;font-size:16pt;text-anchor:middle;" > {code} </text> </g> </svg>""" for (dashed_code, code) in zip(dashed_codes, codes): out_file = code + ".svg" svg = code128.svg(code) with open(out_file, 'w') as o: svg_content = "\n".join(svg.split("\n")[3:-2]) print(template.format(bar=svg_content, code=dashed_code, logo=logo_content), file=o)
from enigma.machine import EnigmaMachine # setup machine according to specs from a daily key sheet: import code128 import os, sys sys.path.insert(1, os.path.join(sys.path[0], '..')) import challenges as c # c.u3c => challenge no. 3 for urban race s=c.u3c with open("u3a_final.svg", "w") as f: f.write(code128.svg("Today is 0x22")) f.close() machine = EnigmaMachine.from_key_sheet( rotors='VII I II', reflector='C', ring_settings='F T P', plugboard_settings='AX EC GB KU PH SO TD VQ WR ZM') # set machine initial starting position machine.set_display('ZWQ') plaintext = s.upper().replace(' ','') ciphertext = machine.process_text(plaintext) f=open('u3b_final.txt','w') i=0 while i<len(ciphertext): f.write(ciphertext[i:i+4]+" ") i+=4 f.write("\n")