Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# app.py
|
2 |
+
from flask import Flask, render_template, request, redirect, url_for
|
3 |
+
from translation_data import translation_dict_A, translation_dict_B
|
4 |
+
|
5 |
+
app = Flask(__name__)
|
6 |
+
|
7 |
+
# リストに変換
|
8 |
+
english_sentences_A = list(translation_dict_A.keys())
|
9 |
+
japanese_translations_A = list(translation_dict_A.values())
|
10 |
+
english_sentences_B = list(translation_dict_B.keys())
|
11 |
+
japanese_translations_B = list(translation_dict_B.values())
|
12 |
+
|
13 |
+
@app.route('/')
|
14 |
+
def index():
|
15 |
+
set_name = request.args.get('set', 'A')
|
16 |
+
index = int(request.args.get('index', 0))
|
17 |
+
if set_name == 'A':
|
18 |
+
english = english_sentences_A[index]
|
19 |
+
japanese = japanese_translations_A[index]
|
20 |
+
else:
|
21 |
+
english = english_sentences_B[index]
|
22 |
+
japanese = japanese_translations_B[index]
|
23 |
+
return render_template('index.html', set_name=set_name, index=index, english=english, japanese=japanese)
|
24 |
+
|
25 |
+
@app.route('/next')
|
26 |
+
def next_card():
|
27 |
+
set_name = request.args.get('set', 'A')
|
28 |
+
index = int(request.args.get('index', 0)) + 1
|
29 |
+
if set_name == 'A' and index >= len(english_sentences_A):
|
30 |
+
index = 0
|
31 |
+
elif set_name == 'B' and index >= len(english_sentences_B):
|
32 |
+
index = 0
|
33 |
+
return redirect(url_for('index', set=set_name, index=index))
|
34 |
+
|
35 |
+
@app.route('/prev')
|
36 |
+
def prev_card():
|
37 |
+
set_name = request.args.get('set', 'A')
|
38 |
+
index = int(request.args.get('index', 0)) - 1
|
39 |
+
if index < 0:
|
40 |
+
if set_name == 'A':
|
41 |
+
index = len(english_sentences_A) - 1
|
42 |
+
else:
|
43 |
+
index = len(english_sentences_B) - 1
|
44 |
+
return redirect(url_for('index', set=set_name, index=index))
|
45 |
+
|
46 |
+
if __name__ == '__main__':
|
47 |
+
app.run(debug=True)
|