Commits

Cédric Bonhomme committed 9ad2271

THe code for the QR Code generation is now in utils.py.

Comments (0)

Files changed (2)

source/pyAggr3g470r.py

 import mongodb
 import feedgetter
 import auth
-#from qrcode.pyqrnative.PyQRNative import QRCode, QRErrorCorrectLevel, CodeOverflowException
-#from qrcode import qr
-
 
 def error_404(status, message, traceback, version):
     """
             description += "\n<br />\n"
         else:
             description = "<p>No description available.</p>\n<br />\n"
-        """
+        
         # Generation of the QR Code for the current article
-        try:
-            os.makedirs("./var/qrcode/")
-        except OSError:
-            pass
-        if not os.path.isfile("./var/qrcode/" + article_id + ".png"):
-            # QR Code generation
-            try:
-                f = qr.QRUrl(url = article["article_link"])
-                f.make()
-            except:
-                f = qr.QRUrl(url = "URL too long.")
-                f.make()
-            f.save("./var/qrcode/"+article_id+".png")
-        """
+        utils.generate_qr_code(article)
 
         # Previous and following articles
         previous, following = None, None
 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
             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
         if url not in feed_link['href']:
             return urllib.parse.urljoin(url, feed_link['href'])
         return feed_link['href']
-    return None
+    return None