File size: 3,694 Bytes
41f9c0c
0cf71d2
41f9c0c
 
 
 
 
 
 
 
f71c727
 
518eeee
 
0cf71d2
 
 
 
41f9c0c
 
f71c727
 
 
 
41f9c0c
 
 
 
 
 
1fc1917
f71c727
41f9c0c
 
1fc1917
518eeee
f71c727
 
 
518eeee
 
 
 
0cf71d2
 
 
 
 
 
 
 
1fc1917
41f9c0c
 
 
 
 
 
 
 
 
f71c727
 
518eeee
 
0cf71d2
 
 
 
41f9c0c
 
 
 
 
 
 
 
 
f71c727
41f9c0c
f71c727
 
518eeee
 
0cf71d2
 
 
 
41f9c0c
 
 
1fc1917
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from flask import Flask, render_template, request, redirect, url_for
from translation_data import translation_dict_A, translation_dict_B, translation_dict_C, translation_dict_D, translation_dict_F, translation_dict_G

app = Flask(__name__)

# リストに変換
english_sentences_A = list(translation_dict_A.keys())
japanese_translations_A = list(translation_dict_A.values())
english_sentences_B = list(translation_dict_B.keys())
japanese_translations_B = list(translation_dict_B.values())
english_sentences_C = list(translation_dict_C.keys())
japanese_translations_C = list(translation_dict_C.values())
english_sentences_D = list(translation_dict_D.keys())
japanese_translations_D = list(translation_dict_D.values())
english_sentences_F = list(translation_dict_F.keys())
japanese_translations_F = list(translation_dict_F.values())
english_sentences_G = list(translation_dict_G.keys())
japanese_translations_G = list(translation_dict_G.values())

@app.route('/')
def portal():
    return render_template('portal.html')

@app.route('/flashcards')
def index():
    set_name = request.args.get('set', 'A')
    index = int(request.args.get('index', 0))
    if set_name == 'A':
        english = english_sentences_A[index]
        japanese = japanese_translations_A[index]
        total = len(english_sentences_A)
    elif set_name == 'B':
        english = english_sentences_B[index]
        japanese = japanese_translations_B[index]
        total = len(english_sentences_B)
    elif set_name == 'C':
        english = english_sentences_C[index]
        japanese = japanese_translations_C[index]
        total = len(english_sentences_C)
    elif set_name == 'D':
        english = english_sentences_D[index]
        japanese = japanese_translations_D[index]
        total = len(english_sentences_D)
    elif set_name == 'F':
        english = english_sentences_F[index]
        japanese = japanese_translations_F[index]
        total = len(english_sentences_F)
    elif set_name == 'G':
        english = english_sentences_G[index]
        japanese = japanese_translations_G[index]
        total = len(english_sentences_G)
    return render_template('index.html', set_name=set_name, index=index, english=english, japanese=japanese, total=total)

@app.route('/next')
def next_card():
    set_name = request.args.get('set', 'A')
    index = int(request.args.get('index', 0)) + 1
    if set_name == 'A' and index >= len(english_sentences_A):
        index = 0
    elif set_name == 'B' and index >= len(english_sentences_B):
        index = 0
    elif set_name == 'C' and index >= len(english_sentences_C):
        index = 0
    elif set_name == 'D' and index >= len(english_sentences_D):
        index = 0
    elif set_name == 'F' and index >= len(english_sentences_F):
        index = 0
    elif set_name == 'G' and index >= len(english_sentences_G):
        index = 0
    return redirect(url_for('index', set=set_name, index=index))

@app.route('/prev')
def prev_card():
    set_name = request.args.get('set', 'A')
    index = int(request.args.get('index', 0)) - 1
    if index < 0:
        if set_name == 'A':
            index = len(english_sentences_A) - 1
        elif set_name == 'B':
            index = len(english_sentences_B) - 1
        elif set_name == 'C':
            index = len(english_sentences_C) - 1
        elif set_name == 'D':
            index = len(english_sentences_D) - 1
        elif set_name == 'F':
            index = len(english_sentences_F) - 1
        elif set_name == 'G':
            index = len(english_sentences_G) - 1
    return redirect(url_for('index', set=set_name, index=index))

if __name__ == '__main__':
    app.run(debug=True, host="0.0.0.0", port=7860)