begin implementing character API fetch routes with rudimentary inefficient paging - character_data.keys() will need caching and surface level data building, perhaps prebuilt.json or runtime var? similar to SeasonList

This commit is contained in:
Xevion
2020-09-14 12:26:01 -05:00
parent 1d9d1d27ad
commit 9cc6dbfa50
2 changed files with 21 additions and 0 deletions

View File

@@ -16,6 +16,9 @@ BASE_DIR = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(BASE_DIR, 'data', 'data.json'), 'r', encoding='utf-8') as file: with open(os.path.join(BASE_DIR, 'data', 'data.json'), 'r', encoding='utf-8') as file:
data = json.load(file) data = json.load(file)
with open(os.path.join(BASE_DIR, 'data', 'characters.json'), 'r', encoding='utf-8') as file:
character_data = json.load(file)
stats = { stats = {
'totals': { 'totals': {
'quote': 0, 'quote': 0,
@@ -86,3 +89,19 @@ def api_quote_neighbors():
quotes = data[season - 1]['episodes'][episode - 1]['scenes'][scene - 1]['quotes'] quotes = data[season - 1]['episodes'][episode - 1]['scenes'][scene - 1]['quotes']
top, below = get_neighbors(quotes, quote - 1, int(request.args.get('distance', 2))) top, below = get_neighbors(quotes, quote - 1, int(request.args.get('distance', 2)))
return jsonify({'above': top, 'below': below}) return jsonify({'above': top, 'below': below})
@current_app.route('/api/characters/')
def api_character_list():
return jsonify(list(character_data.keys()))
@current_app.route('/api/character/<character>/')
def api_character_all(character: str):
return jsonify(character_data[character])
@current_app.route('/api/character/<character>/<int:page>/')
def api_character_paged(character: str, page: int):
index: int = (page - 1) * 10
return jsonify(character_data[character][index: index + 10])

View File

@@ -14,6 +14,8 @@ from typing import Dict, Iterable, List, Optional, Tuple, Union
import enlighten import enlighten
import requests import requests
from server.helpers import character_id
session = requests.Session() session = requests.Session()
BASE_DIR = os.path.dirname(os.path.abspath(__file__)) BASE_DIR = os.path.dirname(os.path.abspath(__file__))