add current anime list to available routes
This commit is contained in:
@@ -8,6 +8,9 @@ from pydantic import BaseModel
|
||||
from rapidfuzz import fuzz
|
||||
from operator import itemgetter
|
||||
|
||||
import boto3
|
||||
import json
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
# Helper functions
|
||||
@@ -143,3 +146,24 @@ async def ag_search(search: Search):
|
||||
anime = anime.pop('score')
|
||||
|
||||
return anime_score_list
|
||||
|
||||
@router.get("/ag-list")
|
||||
async def ag_list():
|
||||
source_name = os.getenv('SOURCE_BUCKET_NAME')
|
||||
|
||||
# Log into AWS
|
||||
session = boto3.Session( aws_access_key_id=os.getenv('ACCESS_KEY'), aws_secret_access_key=os.getenv('SECRET_ACCESS_KEY'))
|
||||
s3 = session.resource('s3')
|
||||
source_bucket = s3.Bucket(source_name)
|
||||
|
||||
# list of anime titles
|
||||
anime_titles = []
|
||||
|
||||
# get titles through S3
|
||||
for obj in source_bucket.objects.filter(Prefix="days/"):
|
||||
if obj.key.endswith("metadata.json"):
|
||||
metadata_file = obj.get()['Body'].read()
|
||||
metadata = json.loads(metadata_file)
|
||||
anime_titles.append(metadata['answer'])
|
||||
|
||||
return json.dumps(anime_titles)
|
||||
|
Reference in New Issue
Block a user