-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8a965d
commit a053143
Showing
10 changed files
with
159 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
/env | ||
/app/__pycache__ | ||
/app/router/__pycache__ | ||
/app/schema/__pycache__ | ||
/app/schema/__pycache__ | ||
/app/service/__pycache__ | ||
/conf/__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
from fastapi import APIRouter, Request | ||
from fastapi.responses import StreamingResponse | ||
|
||
from schema.schemas import UrlData, WifiData, ContactData, GeoLocationData, EmailData, HealthCheck | ||
from service.qr_code_service import url_to_qr_service, wifi_to_qr_service, contact_to_qr_service, geo_to_qr_service, email_to_qr_service | ||
|
||
|
||
router = APIRouter() | ||
|
||
@router.post("/url_to_qr") | ||
async def url_to_qr(request: Request, | ||
info: UrlData) -> StreamingResponse: | ||
|
||
return await url_to_qr_service(request, info) | ||
|
||
|
||
@router.post("/wifi_to_qr") | ||
async def wifi_to_qr(request: Request, | ||
info: WifiData) -> StreamingResponse: | ||
|
||
return await wifi_to_qr_service(request, info) | ||
|
||
|
||
@router.post("/contact_to_qr") | ||
async def contact_to_qr(request: Request, | ||
info: ContactData) -> StreamingResponse: | ||
|
||
return await contact_to_qr_service(request, info) | ||
|
||
|
||
@router.post("/geo_to_qr") | ||
async def geo_to_qr(request: Request, | ||
info: GeoLocationData) -> StreamingResponse: | ||
|
||
return await geo_to_qr_service(request, info) | ||
|
||
|
||
@router.post("/email_to_qr") | ||
async def email_to_qr(request: Request, | ||
info: EmailData) -> StreamingResponse: | ||
|
||
return await email_to_qr_service(request, info) | ||
|
||
|
||
@router.get("/health") | ||
async def get_health() -> HealthCheck: | ||
|
||
return HealthCheck(status="OK") | ||
|
||
# return templates.TemplateResponse("home.html", {"request": request, "qr_data": qr_data}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
import io | ||
import segno | ||
from fastapi import Request, status | ||
from fastapi.responses import StreamingResponse | ||
from segno import helpers | ||
|
||
from schema.schemas import UrlData, WifiData, ContactData, GeoLocationData, EmailData | ||
|
||
|
||
async def url_to_qr_service(request: Request, | ||
info: UrlData) -> StreamingResponse: | ||
|
||
data: str = info.url | ||
qr_data: bytes = segno.make_qr(data, error = 'H') | ||
qr_buffer = io.BytesIO() | ||
qr_data.save(qr_buffer, kind='png', scale=10) | ||
qr_buffer.seek(0) | ||
return StreamingResponse(status_code=status.HTTP_201_CREATED, | ||
content=qr_buffer, | ||
media_type="image/png") | ||
|
||
|
||
async def wifi_to_qr_service(request: Request, | ||
info: WifiData) -> StreamingResponse: | ||
|
||
name: str = info.wifi_name | ||
password: str = info.wifi_password | ||
data: bytes = helpers.make_wifi_data(ssid=name, password=password, security='WPA') | ||
qr_data: bytes = segno.make(data, error = 'H') | ||
qr_buffer = io.BytesIO() | ||
qr_data.save(qr_buffer, kind='png', scale=10) | ||
qr_buffer.seek(0) | ||
return StreamingResponse(status_code=status.HTTP_201_CREATED, | ||
content=qr_buffer, | ||
media_type="image/png") | ||
|
||
|
||
async def contact_to_qr_service(request: Request, | ||
info: ContactData) -> StreamingResponse: | ||
|
||
data: bytes = helpers.make_vcard_data( | ||
displayname = info.name, | ||
name = info.name, | ||
email = info.email, | ||
phone = info.phone, | ||
city = info.city, | ||
org = info.org, | ||
title = info.title, | ||
url = info.url | ||
) | ||
qr_data: bytes = segno.make(data, error = 'H') | ||
qr_buffer = io.BytesIO() | ||
qr_data.save(qr_buffer, kind='png', scale=10) | ||
qr_buffer.seek(0) | ||
return StreamingResponse(status_code=status.HTTP_201_CREATED, | ||
content=qr_buffer, | ||
media_type="image/png") | ||
|
||
|
||
async def geo_to_qr_service(request: Request, | ||
info: GeoLocationData) -> StreamingResponse: | ||
|
||
data: bytes = helpers.make_geo_data(info.latitude, info.longitude) | ||
qr_data: bytes = segno.make(data, error = 'H') | ||
qr_buffer = io.BytesIO() | ||
qr_data.save(qr_buffer, kind='png', scale=10) | ||
qr_buffer.seek(0) | ||
return StreamingResponse(status_code=status.HTTP_201_CREATED, | ||
content=qr_buffer, | ||
media_type="image/png") | ||
|
||
|
||
async def email_to_qr_service(request: Request, | ||
info: EmailData) -> StreamingResponse: | ||
|
||
qr_data: bytes = helpers.make_email( | ||
to = info.to, | ||
subject = info.subject, | ||
body = info.body, | ||
cc = info.cc | ||
) | ||
qr_buffer = io.BytesIO() | ||
qr_data.save(qr_buffer, kind='png', scale=10) | ||
qr_buffer.seek(0) | ||
return StreamingResponse(status_code=status.HTTP_201_CREATED, | ||
content=qr_buffer, | ||
media_type="image/png") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import multiprocessing | ||
import uvicorn | ||
|
||
workers = multiprocessing.cpu_count() * 2 + 1 | ||
bind = '0.0.0.0:8000' | ||
worker_class = 'uvicorn.workers.UvicornWorker' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
version: '3.3' | ||
version: '3.8' | ||
|
||
services: | ||
app: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters