mirror of
https://github.com/Xevion/the-office.git
synced 2025-12-10 08:08:52 -06:00
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:
@@ -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])
|
||||||
|
|||||||
@@ -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__))
|
||||||
|
|||||||
Reference in New Issue
Block a user