-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
91 lines (75 loc) · 2.55 KB
/
main.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# ┌──────────────────────────────────────┐
# │ > to run local server │
# │ uvicorn main:app --reload │
# │ │
# │ > developer : │
# │ @LampStack │
# └──────────────────────────────────────┘
from fastapi import FastAPI
from imdb import Cinemagoer, IMDbError
app = FastAPI()
ia = Cinemagoer()
@app.get("/")
async def root():
return {"status": "error", "message": "to read docs open /docs"}
@app.get("/search/movie")
@app.get("/search/movie/{query}")
async def search_movie(query:str):
try:
movies = ia.search_movie(query)
for i in range(len(movies)):
movies[i]['movieID'] = movies[i].movieID
except IMDbError as e:
return {"status": "error", "message": e}
else:
return {"status": "ok", "result": movies}
@app.get("/search/person")
@app.get("/search/person/{query}")
async def search_person(query:str):
try:
peoples = ia.search_person(query)
for i in range(len(peoples)):
peoples[i]['personID'] = peoples[i].personID
except IMDbError as e:
return {"status": "error", "message": e}
else:
return {"status": "ok", "result": peoples}
@app.get("/get/movie")
@app.get("/get/movie/{query}")
async def get_movie(query:str):
try:
movie = ia.get_movie(query)
except IMDbError as e:
return {"status": "error", "message": e}
else:
return {"status": "ok", "result": movie}
@app.get("/get/person")
@app.get("/get/person/{query}")
async def get_person(query:str):
try:
person = ia.get_person(query)
except IMDbError as e:
return {"status": "error", "message": e}
else:
return {"status": "ok", "result": person}
@app.get("/search/keyword")
@app.get("/search/keyword/{query}")
async def search_keyword(query:str):
try:
keywords = ia.search_keyword(query)
except IMDbError as e:
return {"status": "error", "message": e}
else:
return {"status": "ok", "result": keywords}
@app.get("/get/keyword")
@app.get("/get/keyword/{query}")
async def get_keyword(query:str):
try:
keyword = ia.get_keyword(query)
except IMDbError as e:
return {"status": "error", "message": e}
else:
return {"status": "ok", "result": keyword}