CnJaFlashC-1 / app.py
OzoneAsai's picture
Create app.py
41f9c0c verified
raw
history blame
1.64 kB
# app.py
from flask import Flask, render_template, request, redirect, url_for
from translation_data import translation_dict_A, translation_dict_B
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())
@app.route('/')
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]
else:
english = english_sentences_B[index]
japanese = japanese_translations_B[index]
return render_template('index.html', set_name=set_name, index=index, english=english, japanese=japanese)
@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
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
else:
index = len(english_sentences_B) - 1
return redirect(url_for('index', set=set_name, index=index))
if __name__ == '__main__':
app.run(debug=True)