diff --git a/server/api.py b/server/api.py index f6c5610..03ad577 100644 --- a/server/api.py +++ b/server/api.py @@ -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: 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 = { 'totals': { 'quote': 0, @@ -86,3 +89,19 @@ def api_quote_neighbors(): quotes = data[season - 1]['episodes'][episode - 1]['scenes'][scene - 1]['quotes'] top, below = get_neighbors(quotes, quote - 1, int(request.args.get('distance', 2))) 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//') +def api_character_all(character: str): + return jsonify(character_data[character]) + + +@current_app.route('/api/character///') +def api_character_paged(character: str, page: int): + index: int = (page - 1) * 10 + return jsonify(character_data[character][index: index + 10]) diff --git a/server/process.py b/server/process.py index d417c1f..4d78bb4 100644 --- a/server/process.py +++ b/server/process.py @@ -14,6 +14,8 @@ from typing import Dict, Iterable, List, Optional, Tuple, Union import enlighten import requests +from server.helpers import character_id + session = requests.Session() BASE_DIR = os.path.dirname(os.path.abspath(__file__))