Skip to content

Commit

Permalink
Finish MVP 1
Browse files Browse the repository at this point in the history
  • Loading branch information
debemdeboas committed Oct 5, 2020
1 parent 48e1642 commit c06ab63
Show file tree
Hide file tree
Showing 15 changed files with 103 additions and 0 deletions.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn app:app
27 changes: 27 additions & 0 deletions app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from dotenv import main
from qrcode_generator import create_qrcode
from flask import Flask, request
from flask_bootstrap import Bootstrap
from flask.templating import render_template
from dotenv import load_dotenv
from forms import QRCodeForm

import os

load_dotenv()

app = Flask(__name__)
app.config['SECRET_KEY'] = os.getenv('SECRET_KEY')
bootstrap = Bootstrap(app)

@app.route('/', methods=['POST', 'GET'])
def homepage():
return render_template('index.html', title='QRCode Generator', form=QRCodeForm())

@app.route('/generate_qrcode', methods=['POST'])
def generate_qrcode():
img_path = create_qrcode(request.form['content'])
return render_template('generate_qrcode.html', title='generated QRCode', img = img_path, content = request.form['content'])

if __name__ == "__main__":
app.run(threaded=True, port=9691, host='0.0.0.0')
10 changes: 10 additions & 0 deletions forms.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from flask_wtf import FlaskForm
from wtforms import StringField
from wtforms.validators import InputRequired

class QRCodeForm(FlaskForm):
content = StringField(
label='QRCode content',
description='Link, text, email, phone number... anything!',
validators=[InputRequired()],
)
13 changes: 13 additions & 0 deletions qrcode_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import hashlib
import segno
from datetime import datetime

IMG_OUTPUT_PATH = 'static/qrcodes/'

def generate_qrcode_image(content, err_lvl):
return segno.make(content, error = err_lvl)

def create_qrcode(content, error = 'H'):
filename = IMG_OUTPUT_PATH + hashlib.sha256(f'{content}_{datetime.now()}'.encode('utf-8')).hexdigest() + '.svg'
generate_qrcode_image(content, error).save(filename, scale=10, light='white', dark='black')
return filename
18 changes: 18 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
click==7.1.2
colorama==0.4.3
dominate==2.5.2
Flask==1.1.2
Flask-Bootstrap==3.3.7.1
Flask-WTF==0.14.3
gunicorn==20.0.4
itsdangerous==1.1.0
Jinja2==2.11.2
MarkupSafe==1.1.1
Pillow==7.2.0
python-dotenv==0.14.0
qrcode-artistic==2.1.0
segno==1.3.1
six==1.15.0
visitor==0.1.3
Werkzeug==1.0.1
WTForms==2.3.3
Binary file added static/icon/android-chrome-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icon/android-chrome-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icon/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icon/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icon/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/icon/favicon.ico
Binary file not shown.
1 change: 1 addition & 0 deletions static/icon/site.webmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"name":"","short_name":"","icons":[{"src":"static/icon/android-chrome-192x192.png","sizes":"192x192","type":"image/png"},{"src":"static/icon/android-chrome-512x512.png","sizes":"512x512","type":"image/png"}],"theme_color":"#ffffff","background_color":"#ffffff","display":"standalone"}
12 changes: 12 additions & 0 deletions templates/base.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{% extends "bootstrap/base.html" %}
{% import "bootstrap/wtf.html" as wtf %}

{% block head %}
{{ super() }}
<title>{% block title %}{{ title | default('@debemdeboas') }}{% endblock %}</title>
<link rel="apple-touch-icon" sizes="180x180" href="static/icon/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="static/icon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="static/icon/favicon-16x16.png">
<link rel="manifest" href="static/icon/site.webmanifest">
{% endblock %}
{% block html_atrib %}lang="en"{% endblock %}
10 changes: 10 additions & 0 deletions templates/generate_qrcode.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "base.html" %}

{% block content %}
<div class="container">
<div class="container">
<img src="{{ img }}" alt="QRCode for '{{ content }}'" width="100%">
</div>
<a class="btn btn-primary" href="{{ url_for('homepage') }}" role="button">Generate another!</a>
</div>
{% endblock %}
11 changes: 11 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{% extends "base.html" %}

{% block content %}
<div class="container">
<h1>welcome to the simple and effective qrcode generator (<a href="https://en.wikipedia.org/wiki/KISS_principle">KISS principle</a>)</h1>
<form action="{{ url_for('generate_qrcode') }}" method="POST">
{{ wtf.form_field(form.content) }}
<input class="btn btn-primary" type="submit" value="Generate!">
</form>
</div>
{% endblock %}

0 comments on commit c06ab63

Please sign in to comment.