Generating QR Codes containing vCard data

2011 will be the year of the QR-Code of this I am sure..

In brief, they’re fascinating little 2-dimensional barcodes that can be used to encode up to 2,953 bytes of data. The android app store uses them to encode links to applications, you scan the QR-code and the device pops up a link to the app store for your to download….. Hence my interest!!

I wanted to figure out how to generate these so I decided that combining some of my recent interests (wordpress plugin development and google app engine) and knocking up something to generate QR-codes containing vCard information would be fun and useful.

I’m not going to go into much detail as the source is available and I’m terminally lazy when it comes to explaining code. I used bottle.py as the REST framework (plan on moving it up to GAE, yaml file is there already but because GAE doesn’t have a persistent file system, it’s non trivial to do the permalink) and Uni-Form for the client. Code to generate the QR used pygooglechart and was trivial

vCardTemplate = """BEGIN:VCARD
N:{SURNAME};{FIRSTNAME}
TEL;CELL:{TELMOBILE}
TEL;HOME:{TELHOME}
EMAIL:{EMAIL}
URL:{URL}
END:VCARD"""

class QRMaker:
    def __init__(self):
        self._templateData = vCardTemplate

    def createVCard(self, data):
        logging.debug("In createVCard")
        chart = QRChart(HEIGHT, WIDTH)
        templateData = ""

        for k, v in data.items():
            templateData = self._templateData.replace("{%s}" % k, v)
            self._templateData = templateData

        match = re.sub(r'{\w*\w}', '', templateData)

        chart.add_data(match)

        chart.set_ec('H', 0)
        uid = uuid.uuid1()

        chart.download('static/cache/%s.png' % uid)
        return uid

Part one of this is to generate the QR-codes and is working (for loose values of work) below

Part two will be to extend it to allow a wordpress plugin to display this QR-code on your site.

:: Demo app is available here
:: Source is available here

by Fergal

Bookmark the permalink.

Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">

This site is using OpenAvatar based on

Comment moderation is enabled. Your comment may take some time to appear.

The Periodic Something Else is Digg proof thanks to caching by WP Super Cache