diff --git a/server/.flaskenv b/.flaskenv
similarity index 100%
rename from server/.flaskenv
rename to .flaskenv
diff --git a/client/src/components/SearchResult.vue b/client/src/components/SearchResult.vue
new file mode 100644
index 0000000..1fafa67
--- /dev/null
+++ b/client/src/components/SearchResult.vue
@@ -0,0 +1,104 @@
+
+
+
+
+
+ | {{ quote.speaker }} |
+ {{ quote.text }} |
+
+
+ |
+ |
+
+
+ | {{ quote.speaker }} |
+ {{ quote.text }} |
+
+
+
+
+ Season {{ item.season }} Episode {{ item.episode_rel }} Scene {{ item.section_rel }}
+
+
+
+
+
+
+
+
diff --git a/client/src/components/SearchResults.vue b/client/src/components/SearchResults.vue
index 2941d19..4b9af48 100644
--- a/client/src/components/SearchResults.vue
+++ b/client/src/components/SearchResults.vue
@@ -2,19 +2,21 @@
-
-
- :
-
-
-
-
-
-
- Season {{ item.season }} Episode {{ item.episode }} Scene {{ item.section }}
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -28,7 +30,7 @@
mark, .mark {
padding: 0.02em;
- background-color: #fff500;
+ background-color: #d2ca00;
/*color: #black;*/
/*-webkit-filter: invert(100%);*/
/*filter: invert(100%);*/
@@ -44,7 +46,12 @@
}
diff --git a/server/api.py b/server/api.py
index 58910a3..f6c5610 100644
--- a/server/api.py
+++ b/server/api.py
@@ -8,9 +8,9 @@ import os
from copy import deepcopy
import flask_wtf
-from flask import current_app, jsonify
+from flask import current_app, jsonify, request
-from server.helpers import default
+from server.helpers import default, get_neighbors
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:
@@ -25,7 +25,6 @@ stats = {
}
}
-
stats['totals']['season'] += len(default(data, []))
for season in data:
stats['totals']['episode'] += len(default(season.get('episodes'), []))
@@ -77,3 +76,13 @@ def api_data():
Season data route
"""
return jsonify(data)
+
+
+@current_app.route('/api/quote_surround')
+def api_quote_neighbors():
+ season, episode = int(request.args.get('season')), int(request.args.get('episode'))
+ scene, quote = int(request.args.get('scene')), int(request.args.get('quote'))
+
+ 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})
diff --git a/server/create_app.py b/server/create_app.py
index c67a8e8..3aa94d6 100644
--- a/server/create_app.py
+++ b/server/create_app.py
@@ -11,7 +11,7 @@ from flask_wtf.csrf import CSRFProtect
from server.config import configs
csrf = CSRFProtect()
-cors = CORS(resources={r'/*': {'origins': '*'}})
+cors = CORS(resources={r'/api/*': {'origins': '*'}})
def create_app(env=None):
diff --git a/server/helpers.py b/server/helpers.py
index 9351a65..499aac1 100644
--- a/server/helpers.py
+++ b/server/helpers.py
@@ -1,9 +1,32 @@
+"""
+helpers.py
+
+
+"""
+
+from typing import List, Tuple
+
episode_counts = [6, 22, 23, 14, 26, 24, 24, 24, 23]
def check_validity(season: int, episode: int):
+ """Shorthand function for checking if a specific episode is valid."""
return (1 <= season <= 9) and (1 <= episode <= episode_counts[season])
def default(value, other):
+ """Value default, similar to dict.get, but better."""
return value if value is not None else other
+
+
+def get_neighbors(array: List, index: int, distance: int = 2) -> Tuple[List, List]:
+ """Get neighbors above and below a specific index in an array. Returns maximum number of items possible."""
+ top, below = [], []
+ for i in range(1, distance + 1):
+ top_index = index - i
+ below_index = index + i
+ if top_index >= 0:
+ top.append(array[top_index])
+ if below_index < len(array):
+ below.append(array[below_index])
+ return top[::-1], below[::-1]