-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflashmachine_API.py
61 lines (41 loc) · 1.17 KB
/
flashmachine_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
from typing import Optional, List
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from naverDictScraper import getDefinition
class Word_Request(BaseModel):
word_array: List[str]
app = FastAPI()
origins = [
"https://flashmachine.herokuapp.com",
"http://localhost:3000"
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get('/')
def read_root():
return {"Flashmachine API status:": "Operational"}
@app.get('/single_word/{word}')
def get_single_word(word: str):
result = getDefinition(word)
return result
@app.get('/words/{joined_word}')
def get_multiple_words(joined_word: str):
word_list = joined_word.split('_')
result = []
for w in word_list:
result.append(getDefinition(w))
return(result)
@app.post('/request_words/')
async def get_words_with_JSON(word_request: Word_Request):
print('Confirm receipt of word request:')
print(word_request)
result = []
for w in word_request.word_array:
result.append(getDefinition(w))
return result