mirror of
https://github.com/fergalmoran/qrmaker.git
synced 2025-12-22 10:00:50 +00:00
Fixed write perms but in QRMaker.py
This commit is contained in:
@@ -3,40 +3,49 @@ import logging
|
|||||||
import re
|
import re
|
||||||
import uuid
|
import uuid
|
||||||
import shutil
|
import shutil
|
||||||
|
import os
|
||||||
|
|
||||||
HEIGHT = 220
|
HEIGHT = 210
|
||||||
WIDTH = 220
|
WIDTH = 210
|
||||||
|
|
||||||
vCardTemplate = """BEGIN:VCARD
|
vCardTemplate = '''BEGIN:VCARD
|
||||||
N:{SURNAME};{FIRSTNAME}
|
N:{SURNAME};{FIRSTNAME}
|
||||||
TEL;CELL:{TELMOBILE}
|
TEL;CELL:{TELMOBILE}
|
||||||
TEL;HOME:{TELHOME}
|
TEL;HOME:{TELHOME}
|
||||||
EMAIL:{EMAIL}
|
EMAIL:{EMAIL}
|
||||||
URL:{URL}
|
URL:{URL}
|
||||||
END:VCARD"""
|
END:VCARD'''
|
||||||
|
|
||||||
class QRMaker:
|
class QRMaker:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._templateData = vCardTemplate
|
self._templateData = vCardTemplate
|
||||||
|
|
||||||
def createVCard(self, data):
|
def createVCard(self, data):
|
||||||
logging.debug("In createVCard")
|
try:
|
||||||
|
logging.debug('In createVCard')
|
||||||
chart = QRChart(HEIGHT, WIDTH)
|
chart = QRChart(HEIGHT, WIDTH)
|
||||||
templateData = ""
|
templateData = ''
|
||||||
|
logging.debug('Parsing form')
|
||||||
for k, v in data.items():
|
for k, v in data.items():
|
||||||
templateData = self._templateData.replace("{%s}" % k, v)
|
templateData = self._templateData.replace('{%s}' % k, v)
|
||||||
self._templateData = templateData
|
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)
|
chart.set_ec('H', 0)
|
||||||
uid = uuid.uuid1()
|
uid = uuid.uuid1()
|
||||||
|
logging.debug('Downloading image')
|
||||||
chart.download('static/cache/%s.png' % uid)
|
filePath = '%s/../static/cache/%s.png' % (os.path.dirname(__file__), uid)
|
||||||
|
logging.debug('Downloading ' + filePath)
|
||||||
|
chart.download(filePath)
|
||||||
return uid
|
return uid
|
||||||
|
except ex:
|
||||||
|
logging.debug('Unhandled exception')
|
||||||
|
logging.exception('Unhandled exception')
|
||||||
|
|
||||||
def generatePermalink(self, id):
|
def generatePermalink(self, id):
|
||||||
shutil.copyfile(
|
shutil.copyfile(
|
||||||
@@ -44,3 +53,4 @@ class QRMaker:
|
|||||||
'static/images/permalinked/%s.png' % id
|
'static/images/permalinked/%s.png' % id
|
||||||
)
|
)
|
||||||
return 'static/images/permalinked/%s.png' % id
|
return 'static/images/permalinked/%s.png' % id
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user