From 0f1d449e690412b84e598088ec251d2760b5bdd9 Mon Sep 17 00:00:00 2001 From: lza_menace Date: Sun, 20 Dec 2020 17:04:27 -0800 Subject: [PATCH] add qr codes to posts --- requirements.txt | 2 ++ suchwow/routes/post.py | 11 ++++++++++- suchwow/templates/post/read.html | 3 +++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index d0006cc..b3520aa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,3 +5,5 @@ peewee gunicorn six praw +qrcode +Pillow diff --git a/suchwow/routes/post.py b/suchwow/routes/post.py index 6d89958..b5b40e0 100644 --- a/suchwow/routes/post.py +++ b/suchwow/routes/post.py @@ -1,4 +1,7 @@ from os import path, remove +from io import BytesIO +from base64 import b64encode +from qrcode import make as qrcode_make from flask import render_template, Blueprint, request, session, flash from flask import send_from_directory, redirect, url_for, current_app from werkzeug.utils import secure_filename @@ -31,6 +34,8 @@ def top(): @bp.route("/post/") def read(id): + _address_qr = BytesIO() + qr_code = None if Post.filter(id=id): wallet = wownero.Wallet() post = Post.get(id=id) @@ -41,6 +46,9 @@ def read(id): if wallet.connected: address = wallet.get_address(account=post.account_index) transfers = wallet.transfers(account=post.account_index) + qr_uri = f'wownero:{address}?tx_description=suchwow%20post%20{post.id}' + address_qr = qrcode_make(qr_uri).save(_address_qr) + qr_code = b64encode(_address_qr.getvalue()).decode() else: address = "?" transfers = "?" @@ -48,7 +56,8 @@ def read(id): "post/read.html", post=post, address=address, - transfers=transfers + transfers=transfers, + qr_code=qr_code ) else: flash("No meme there, brah") diff --git a/suchwow/templates/post/read.html b/suchwow/templates/post/read.html index 6e78c92..cd585e7 100644 --- a/suchwow/templates/post/read.html +++ b/suchwow/templates/post/read.html @@ -24,6 +24,9 @@

Payments

Vote for this post by sending WOW to the following address:
{{ address }}

+ {% if qr_code %} +

+ {% endif %}
WOW Received
{% if transfers.in %}