add Home and Episode routes, full quote display and viewing, simple quote counter, fixed episode list breaking sections with soft-copy, column changes

This commit is contained in:
Xevion
2020-08-04 20:30:47 -05:00
parent 5fdbe86eae
commit a2125cfa44
7 changed files with 169 additions and 12 deletions

View File

@@ -5,14 +5,35 @@ Provides a accessible protected backend API. JSON I/O only, CSRF protected.
"""
import json
import os
from copy import deepcopy
import flask_wtf
from flask import current_app, jsonify
from server.helpers import default
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)
stats = {
'totals': {
'quote': 0,
'scene': 0,
'episode': 0,
'season': 0
}
}
stats['totals']['season'] += len(default(data, []))
for season in data:
stats['totals']['episode'] += len(default(season.get('episodes'), []))
for episode in season['episodes']:
stats['totals']['scene'] += len(default(episode.get('scenes'), []))
for scene in default(episode.get('scenes'), []):
stats['totals']['quote'] += len(default(scene.get('quotes'), []))
@current_app.route('/api/csrf/')
def api_csrf():
@@ -24,6 +45,17 @@ def api_csrf():
return jsonify(flask_wtf.csrf.generate_csrf())
@current_app.route('/api/episode/<int:season>/<int:episode>/')
def api_episode(season: int, episode: int):
print(data[season - 1]['episodes'][episode - 1])
return jsonify(data[season - 1]['episodes'][episode - 1])
@current_app.route('/api/stats/')
def api_stats():
return jsonify(stats)
@current_app.route('/api/episodes/')
def api_episodes():
"""
@@ -31,7 +63,7 @@ def api_episodes():
Used for the left side season bar.
"""
seasons = []
copy = list(data)
copy = deepcopy(data)
for season in copy:
for episode in season.get('episodes'):
if 'scenes' in episode.keys():