-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
64 lines (50 loc) · 1.63 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from flask import Flask,request,send_file
import qrcode
import os
import pathlib
from pathlib import Path
script_directory = pathlib.Path(__file__).parent.resolve()
template = """BEGIN:VCARD
VERSION:4.0
N:{last_name};{first_name}.;
ORG:{company}
TEL;TYPE#mobile,voice;VALUE#uri:tel:{mobile_phone}
TEL;TYPE#work,voice;VALUE#uri:tel:{work_phone}
ADR;TYPE#WORK;PREF#1:{work_address_line_1};{work_address_city};{work_address_stage_code};{work_address_pin};{work_address_country}
EMAIL:{email}
URL:{url}
REV:20080424T195243Z
x-qq:21588891
END:VCARD"""
def create_qr_code_image(qr_code_data,file_path):
qr = qrcode.QRCode(
version=2,
error_correction=qrcode.constants.ERROR_CORRECT_L,
box_size=10,
border=2,
)
qr.add_data(qr_code_data)
qr.make(fit=True)
img = qr.make_image(fill_color="blue", back_color="white")
img.save(file_path)
app= Flask(__name__)
@app.route("/result",methods=["POST","GET"])
def result():
output =request.get_json()
patho=os.path.join(script_directory,'qrs')
path_dir=Path(patho)
if path_dir.is_dir():
filen=filen=patho+'/'+output['last_name']+'_'+output['company']+'.png'
else:
os.mkdir(patho)
filen=patho+'/'+output['last_name']+'_'+output['company']+'.png'
if len(output.keys()) <3:
return {"status":"Bad Response"}
else:
qdata=template.format(**output)
create_qr_code_image(
qr_code_data=qdata,file_path=filen)
return send_file(filen)
# return send_file(filen)
if __name__=='__main__':
app.run()