File size: 1,547 Bytes
28bbb93
 
 
 
a829725
0b89ddd
28bbb93
 
 
 
0b89ddd
 
 
 
 
 
 
 
 
 
28bbb93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a829725
28bbb93
 
 
 
 
 
 
 
 
 
 
 
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

import asyncio
from concurrent.futures import ThreadPoolExecutor

from fastapi import FastAPI, Response, Request
from starlette.middleware.cors import CORSMiddleware
# import json
# from load_data import get_design_data, get_design_resolutions_for_shop
from createlookalike import create_feature_files
from schemas import Shop

app = FastAPI()
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],  # Allows all origins
    allow_credentials=True,
    allow_methods=["*"],  # Allows all methods
    allow_headers=["*"],  # Allows all headers
)


API_TOKEN = '34dsadfF$$%#$TGREGEFGE%Q*)(*&%'


executor = ThreadPoolExecutor()


# ---------------------------------------------------------------------------
# - Token auth method -
# ---------------------------------------------------------------------------
def check_auth(authorization_header):
    if authorization_header == API_TOKEN:
        return True
    else:
        return False





@app.get("/")
async def root():
    return {"message": "where are you looking for?"}






@app.post("/lal_for_shop")
async def submit_async_task(request: Request, response: Response, shop: Shop):
    loop = asyncio.new_event_loop()
    authorization_token = request.headers.get("Authorization", None)
    check_token = True  # check_auth(authorization_token)
    if check_token:
        task = asyncio.create_task(create_feature_files(shop))
        return {"message": f"shop calculation for shop {shop.id} submitted"}
    else:
        response.status_code = 401
        return response