forked from iravivarma/QRmenu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqr_api.py
65 lines (49 loc) · 1.41 KB
/
qr_api.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
65
# -*- coding: utf-8 -*-
"""
Created on Tue Dec 1 00:09:10 2020
@author: Ravi Varma Injeti
"""
from fastapi import FastAPI, Request
from pydantic import BaseModel
from fastapi.encoders import jsonable_encoder
import qrcode
import uvicorn
app = FastAPI()
class User(BaseModel):
id : int
hotel_name : str
location_name : str
email_id : str
contact : int
external_data = {
'id' : '12',
'hotel_name' : 'santosh',
'location_name' : 'kukatpally',
'email_id' : '[email protected]',
'contact' : '9492770572',
}
# user = User(**external_data)
# print(user.id)
# #> 123
# print(repr(user.hotel_name))
# #> datetime.datetime(2019, 6, 1, 12, 22)
# print(user.location_name)
# #> [1, 2, 3]
# print(user.dict())
@app.get("/items")
async def update_item(request: Request):
json_compatible_item_data = external_data#jsonable_encoder(item)
print(json_compatible_item_data)
qr_code = qrcode.QRCode(version = 1,
box_size=10,
border = 4)
print(qr_code)
qr_code.add_data(json_compatible_item_data)
qr_code.make(fit = True)
print('image')
qr_image = qr_code.make_image(fill = 'black', back_color = 'yellow')
print("some")
# print(dict(User)
return external_data
if __name__ == "__main__":
uvicorn.run(app, host="127.0.0.1", port=5000)