Merge branch 'main' of https://github.com/nmelone/flask-practice
This commit is contained in:
Binary file not shown.
18
app.py
18
app.py
@@ -1,7 +1,7 @@
|
|||||||
from flask import Flask, render_template, request, redirect, url_for, jsonify
|
from flask import Flask, render_template, request, redirect, url_for, jsonify
|
||||||
from models import db, Item
|
from models import db, Item
|
||||||
from datetime import datetime as dt
|
from datetime import datetime as dt
|
||||||
import requests
|
import requests, csv
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///items.db'
|
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///items.db'
|
||||||
@@ -83,5 +83,21 @@ def get_weather():
|
|||||||
# Handle errors
|
# Handle errors
|
||||||
return f"An error occurred: {e}"
|
return f"An error occurred: {e}"
|
||||||
|
|
||||||
|
def load_vocab(csv_filename):
|
||||||
|
vocab_list = []
|
||||||
|
with open(csv_filename, newline='', encoding='utf-8') as csvfile:
|
||||||
|
reader = csv.reader(csvfile)
|
||||||
|
for row in reader:
|
||||||
|
hiragana_katakana, kanji, english = row
|
||||||
|
japanese = kanji if kanji else hiragana_katakana # Use kanji if available, otherwise use kana
|
||||||
|
vocab_list.append((japanese, english))
|
||||||
|
return vocab_list
|
||||||
|
|
||||||
|
@app.route('/vocabulary')
|
||||||
|
def vocabulary():
|
||||||
|
vocab_list = load_vocab('static/vocab.csv') # Ensure your CSV is in the 'static' folder
|
||||||
|
return render_template('vocabulary.html', vocab_list=vocab_list)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
app.run(debug=True)
|
app.run(debug=True)
|
||||||
|
|||||||
1137
static/vocab.csv
Normal file
1137
static/vocab.csv
Normal file
File diff suppressed because it is too large
Load Diff
@@ -17,6 +17,7 @@
|
|||||||
<a href="{{ url_for('get_weather') }}">Weather</a>
|
<a href="{{ url_for('get_weather') }}">Weather</a>
|
||||||
<a href="{{ url_for('rank') }}">Relative Rank</a>
|
<a href="{{ url_for('rank') }}">Relative Rank</a>
|
||||||
<a href="{{ url_for('motion') }}">Motion Graphics</a>
|
<a href="{{ url_for('motion') }}">Motion Graphics</a>
|
||||||
|
<a href="{{ url_for('vocabulary') }}">Vocabulary</a>
|
||||||
<a href="{{ url_for('about') }}">About</a>
|
<a href="{{ url_for('about') }}">About</a>
|
||||||
</nav>
|
</nav>
|
||||||
</header>
|
</header>
|
||||||
|
|||||||
20
templates/vocabulary.html
Normal file
20
templates/vocabulary.html
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{% extends "base.html" %}
|
||||||
|
{% block content %}
|
||||||
|
<h1>Japanese Vocabulary</h1>
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>Japanese</th>
|
||||||
|
<th>English</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% for japanese, english in vocab_list %}
|
||||||
|
<tr>
|
||||||
|
<td>{{ japanese }}</td>
|
||||||
|
<td>{{ english }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% endblock %}
|
||||||
Reference in New Issue
Block a user