first commit
This commit is contained in:
commit
1afee95737
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
/.venv
|
||||||
|
/__pycache__
|
108
codegen.py
Normal file
108
codegen.py
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
import qrcode
|
||||||
|
import os
|
||||||
|
from io import BytesIO
|
||||||
|
from flask import Flask, send_file, request, render_template_string, render_template
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
def load(file):
|
||||||
|
path = os.path.dirname(os.path.realpath(__file__))
|
||||||
|
with open(f"{path}/webpage/{file}") as f:
|
||||||
|
return f.read()
|
||||||
|
|
||||||
|
@app.route('/', methods=['GET', 'POST'])
|
||||||
|
def index():
|
||||||
|
if request.method == 'POST':
|
||||||
|
qrtype = request.form.get('type')
|
||||||
|
elif request.method == 'GET':
|
||||||
|
qrtype = request.args.get('type')
|
||||||
|
else:
|
||||||
|
qrtype = "LINK"
|
||||||
|
|
||||||
|
if qrtype == "LINK":
|
||||||
|
form = f"""
|
||||||
|
<h2>Enter Url:</h2>
|
||||||
|
<form action="" method="get" enctype="multipart/form-data" id="uploadForm">
|
||||||
|
<input type="hidden" name="type" value="LINK">
|
||||||
|
<input type="text" name="link" id="link" />
|
||||||
|
<br><br>
|
||||||
|
<input type="submit" value="Upload" id="submitButton" />
|
||||||
|
<p id="error" style="color: red; display: none;">File size must be below !MAXFILESIZEHERE! MB.</p>
|
||||||
|
</form>
|
||||||
|
"""
|
||||||
|
elif qrtype == "MAIL":
|
||||||
|
form = f"""
|
||||||
|
<h2>Enter Email:</h2>
|
||||||
|
<form action="" method="get" enctype="multipart/form-data" id="uploadForm">
|
||||||
|
<input type="hidden" name="type" value="EMAIL">
|
||||||
|
<input type="text" name="link" id="link" />
|
||||||
|
<br><br>
|
||||||
|
<input type="submit" value="Upload" id="submitButton" />
|
||||||
|
<p id="error" style="color: red; display: none;">File size must be below !MAXFILESIZEHERE! MB.</p>
|
||||||
|
</form>
|
||||||
|
"""
|
||||||
|
else:
|
||||||
|
form = f"""
|
||||||
|
<h2>Enter Telephone:</h2>
|
||||||
|
<form action="" method="get" enctype="multipart/form-data" id="uploadForm">
|
||||||
|
<input type="hidden" name="type" value="TEL">
|
||||||
|
<input type="text" name="link" id="link" />
|
||||||
|
<br><br>
|
||||||
|
<input type="submit" value="Upload" id="submitButton" />
|
||||||
|
<p id="error" style="color: red; display: none;">File size must be below !MAXFILESIZEHERE! MB.</p>
|
||||||
|
</form>
|
||||||
|
"""
|
||||||
|
|
||||||
|
if request.method == 'POST':
|
||||||
|
qrtype = request.form.get('type')
|
||||||
|
elif request.method == 'GET':
|
||||||
|
qrtype = request.args.get('type')
|
||||||
|
|
||||||
|
codeimg = "<h2> fill out info to generate qr code </h2>"
|
||||||
|
if qrtype:
|
||||||
|
print(qrtype)
|
||||||
|
try:
|
||||||
|
if qrtype == "LINK":
|
||||||
|
codeimg = f'<img src="qrcode?link={request.args.get('link')}"'
|
||||||
|
elif qrtype == "MAIL":
|
||||||
|
codeimg = f'<img src="qrcode?link=MAILTO:{request.args.get('link')}">'
|
||||||
|
elif qrtype == "TEL":
|
||||||
|
codeimg = f'<img src="qrcode?link=TEL:{request.args.get('link')}" width="400" height="400">'
|
||||||
|
except:
|
||||||
|
print("nocontent")
|
||||||
|
codeimg = "<h2> fill out info to generate qr code </h2>"
|
||||||
|
else:
|
||||||
|
codeimg = "<h2> fill out info to generate qr code </h2>"
|
||||||
|
print(codeimg)
|
||||||
|
return render_template("home.html", form=form, codeimg=codeimg)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/qrcode', methods=['GET', 'POST'])
|
||||||
|
def generate_qrcode():
|
||||||
|
if request.method == 'POST':
|
||||||
|
link = request.form.get('link')
|
||||||
|
else:
|
||||||
|
link = request.args.get('link')
|
||||||
|
|
||||||
|
if not link:
|
||||||
|
return "No link provided", 400
|
||||||
|
|
||||||
|
qr = qrcode.QRCode(
|
||||||
|
version=1,
|
||||||
|
error_correction=qrcode.constants.ERROR_CORRECT_L,
|
||||||
|
box_size=10,
|
||||||
|
border=4,
|
||||||
|
)
|
||||||
|
qr.add_data(link)
|
||||||
|
qr.make(fit=True)
|
||||||
|
|
||||||
|
img = qr.make_image(fill_color="black", back_color="white")
|
||||||
|
buffered = BytesIO()
|
||||||
|
img.save(buffered, format="PNG")
|
||||||
|
buffered.seek(0)
|
||||||
|
|
||||||
|
return send_file(buffered, mimetype='image/png')
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
app.run(host='0.0.0.0', port=8080, debug=True)
|
98
templates/home.html
Normal file
98
templates/home.html
Normal file
@ -0,0 +1,98 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<title>Here To There</title>
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Montserrat:wght@400;500;700&display=swap" rel="stylesheet">
|
||||||
|
<style>
|
||||||
|
body {
|
||||||
|
font-family: 'Montserrat', sans-serif;
|
||||||
|
background: linear-gradient(90deg, hsla(198, 100%, 50%, 1) 0%, hsla(188, 92%, 49%, 1) 48%, hsla(201, 100%, 49%, 1) 97%);
|
||||||
|
text-align: center;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
height: 100vh;
|
||||||
|
margin: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.title,
|
||||||
|
.main {
|
||||||
|
background-color: hsl(0, 0%, 22%);
|
||||||
|
backdrop-filter: blur(10px);
|
||||||
|
color: white;
|
||||||
|
padding: 20px;
|
||||||
|
margin: 20px;
|
||||||
|
border-radius: 20px;
|
||||||
|
width: fit-content;
|
||||||
|
}
|
||||||
|
|
||||||
|
.upload,
|
||||||
|
.download {
|
||||||
|
color: white;
|
||||||
|
border-radius: 20px;
|
||||||
|
background-color: #393939;
|
||||||
|
margin: 20px auto;
|
||||||
|
padding: 20px;
|
||||||
|
width: 300px;
|
||||||
|
height: 200px;
|
||||||
|
}
|
||||||
|
|
||||||
|
input,
|
||||||
|
button {
|
||||||
|
border-radius: 20px;
|
||||||
|
padding: 10px;
|
||||||
|
background-color: rgb(79, 79, 79);
|
||||||
|
border: none;
|
||||||
|
color: rgb(222, 222, 222);
|
||||||
|
}
|
||||||
|
|
||||||
|
.types a {
|
||||||
|
text-decoration: none;
|
||||||
|
color: white;
|
||||||
|
transition: all .3s;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.types a:hover {
|
||||||
|
transform: scale(1.3);
|
||||||
|
color: rgb(87, 87, 87);
|
||||||
|
}
|
||||||
|
|
||||||
|
.types a:active {
|
||||||
|
color: rgb(0, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
.main table {
|
||||||
|
margin: auto;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
<div class="title">
|
||||||
|
<h1>QR Code Generator</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="main">
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td class="types">
|
||||||
|
<a href="?type=LINK"><h1>Link</h1></a>
|
||||||
|
<a href="?type=TEL"><h1>Telephone</h1></a>
|
||||||
|
<a href="?type=MAIL"><h1>Email</h1></a>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
<div class="upload">
|
||||||
|
{{ form|safe }}
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
<td>
|
||||||
|
{{ codeimg|safe }}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
Loading…
x
Reference in New Issue
Block a user