diff options
| author | Yuval Adam <yuval@y3xz.com> | 2015-07-07 23:05:18 +0300 |
|---|---|---|
| committer | Yuval Adam <yuval@y3xz.com> | 2015-07-07 23:05:18 +0300 |
| commit | 0d1f505237a8594e86639e2c7aa52adefa90ccdd (patch) | |
| tree | fceef5aa36f06a0a381fa1ba6e50c5b81389d293 | |
| parent | 8949d60b02b61d31806935baec99277382877f60 (diff) | |
Cleanup
| -rw-r--r-- | modes.py | 18 |
1 files changed, 9 insertions, 9 deletions
@@ -1,6 +1,7 @@ import cups from PIL import Image, ImageDraw, ImageFont +from datetime import datetime BASE_IMAGE = 'base.jpg' BASE_FONT = 'cutive.ttf' @@ -10,28 +11,27 @@ PRINTER = 'Canon_iP7200_series' class ModesPrinter(object): def __init__(self, imstr): - username, date, dominants, matrix = imstr.split('|') + username, d, dominants, matrix = imstr.split('|') self.username = username - self.month = date[:2] - self.year = date[2:] + self.date = datetime.strptime(d, '%m%Y').date() self.dominants = [dominants[:6], dominants[6:]] self.matrix = bin(int(matrix, 16))[5:] def _debug(self): - print(self.username, self.month, self.year, self.dominants, self.matrix) + print(self.username, self.date.month, self.date.year, self.dominants, self.matrix) def draw_image(self): - im = Image.open('base.jpg') + im = Image.open(BASE_IMAGE) draw = ImageDraw.Draw(im) - font = ImageFont.truetype('cutive.ttf', 14) - draw.text((10, 25), 'world', fonts=font) + font = ImageFont.truetype('cutive.ttf', 32) + draw.text((10, 25), '@{} / {}'.format(self.username, self.date.strftime('%B %Y')), font=font) im.show() - def do_print(): + def print_image(): conn = cups.Connection() conn.printFile(PRINTER, 'base.jpg', 'title', {}) if __name__ == '__main__': imstr = 'yuv.adm|062015|9A8D6D736489|eff51f2af82c06071120a' mp = ModesPrinter(imstr) - mp._debug() + mp.draw_image() |
