|
from fastapi import FastAPI |
|
from pydantic import BaseModel |
|
import os |
|
|
|
aa = os.getenv("a") |
|
passw = os.getenv("as") |
|
|
|
app = FastAPI() |
|
print(aa) |
|
|
|
Greet = [] |
|
Bye = [] |
|
Sleep = [] |
|
Care = [] |
|
|
|
class Operation(BaseModel): |
|
a: str |
|
b: str |
|
c: str |
|
|
|
@app.get("/") |
|
def greet_json(): |
|
return {"Hello": "World!"} |
|
|
|
@app.post("/add/") |
|
async def add(op: Operation): |
|
if op.a == passw: |
|
target_list = None |
|
if op.b == 'Greet': |
|
target_list = Greet |
|
elif op.b == 'Bye': |
|
target_list = Bye |
|
elif op.b == 'Sleep': |
|
target_list = Sleep |
|
elif op.b == 'Care': |
|
target_list = Care |
|
|
|
if target_list is not None: |
|
target_list.append(op.c) |
|
return {"result": target_list} |
|
else: |
|
return {"result": "Invalid category"} |
|
else: |
|
return {"result": "Invalid operation"} |
|
|
|
@app.post("/remove/") |
|
async def remove(op: Operation): |
|
if op.a == 'Check': |
|
target_list = None |
|
if op.b == 'Greet': |
|
target_list = Greet |
|
elif op.b == 'Bye': |
|
target_list = Bye |
|
elif op.b == 'Sleep': |
|
target_list = Sleep |
|
elif op.b == 'Care': |
|
target_list = Care |
|
|
|
if target_list is not None: |
|
if op.c in target_list: |
|
target_list.remove(op.c) |
|
return {"result": target_list} |
|
else: |
|
return {"result": "Element not found in the list"} |
|
else: |
|
return {"result": "Invalid category"} |
|
else: |
|
return {"result": "Invalid operation"} |
|
|
|
|
|
@app.post("/check/") |
|
async def add(op: Operation): |
|
if op.a == 'Check': |
|
target_list = None |
|
if op.b == 'Greet': |
|
target_list = Greet |
|
elif op.b == 'Bye': |
|
target_list = Bye |
|
elif op.b == 'Sleep': |
|
target_list = Sleep |
|
elif op.b == 'Care': |
|
target_list = Care |
|
if target_list is not None: |
|
return {"result": target_list} |
|
else: |
|
return {"result": "Invalid operation"} |