From 329fa76fae015c8f7faee17dd498e8e87125477b Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Wed, 3 Apr 2013 08:26:27 +0200 Subject: THe code for the QR Code generation is now in utils.py. --- source/utils.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'source/utils.py') diff --git a/source/utils.py b/source/utils.py index 09056bbe..d470456d 100755 --- a/source/utils.py +++ b/source/utils.py @@ -41,6 +41,12 @@ import operator import calendar import html.entities +try: + from qrcode.pyqrnative.PyQRNative import QRCode, QRErrorCorrectLevel, CodeOverflowException + from qrcode import qr +except: + pass + import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText @@ -80,6 +86,23 @@ def detect_url_errors(list_of_urls): errors.append((url, e.reason.errno ,e.reason.strerror)) return errors +def generate_qr_code(article): + """ + Generated a QR Code for the article given in parameter. + """ + try: + os.makedirs("./var/qrcode/") + except OSError: + pass + if not os.path.isfile("./var/qrcode/" + article["article_id"] + ".png"): + # QR Code generation + try: + f = qr.QRUrl(url = article["article_link"]) + f.make() + f.save("./var/qrcode/" + article["article_id"] + ".png") + except: + pass + def clear_string(data): """ Clear a string by removing HTML tags, HTML special caracters @@ -237,4 +260,4 @@ def search_feed(url): if url not in feed_link['href']: return urllib.parse.urljoin(url, feed_link['href']) return feed_link['href'] - return None \ No newline at end of file + return None -- cgit