diff --git a/qrmaker/QRMaker.py b/qrmaker/QRMaker.py index e6f899f..44ec077 100644 --- a/qrmaker/QRMaker.py +++ b/qrmaker/QRMaker.py @@ -3,40 +3,49 @@ import logging import re import uuid import shutil +import os -HEIGHT = 220 -WIDTH = 220 +HEIGHT = 210 +WIDTH = 210 -vCardTemplate = """BEGIN:VCARD +vCardTemplate = '''BEGIN:VCARD N:{SURNAME};{FIRSTNAME} TEL;CELL:{TELMOBILE} TEL;HOME:{TELHOME} EMAIL:{EMAIL} URL:{URL} -END:VCARD""" +END:VCARD''' class QRMaker: def __init__(self): self._templateData = vCardTemplate def createVCard(self, data): - logging.debug("In createVCard") - chart = QRChart(HEIGHT, WIDTH) - templateData = "" + try: + logging.debug('In createVCard') + chart = QRChart(HEIGHT, WIDTH) + templateData = '' + logging.debug('Parsing form') + for k, v in data.items(): + templateData = self._templateData.replace('{%s}' % k, v) + self._templateData = templateData - for k, v in data.items(): - templateData = self._templateData.replace("{%s}" % k, v) - self._templateData = templateData + logging.debug('Parsed form..') - match = re.sub(r'{\w*\w}', '', templateData) + match = re.sub(r'{\w*\w}', '', templateData) - chart.add_data(match) + chart.add_data(match) - chart.set_ec('H', 0) - uid = uuid.uuid1() - - chart.download('static/cache/%s.png' % uid) - return uid + chart.set_ec('H', 0) + uid = uuid.uuid1() + logging.debug('Downloading image') + filePath = '%s/../static/cache/%s.png' % (os.path.dirname(__file__), uid) + logging.debug('Downloading ' + filePath) + chart.download(filePath) + return uid + except ex: + logging.debug('Unhandled exception') + logging.exception('Unhandled exception') def generatePermalink(self, id): shutil.copyfile( @@ -44,3 +53,4 @@ class QRMaker: 'static/images/permalinked/%s.png' % id ) return 'static/images/permalinked/%s.png' % id +