Skip to content

Commit

Permalink
Front-end table generation
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyEye-FAST committed Jul 24, 2024
1 parent ae13608 commit 0948c01
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/update.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install requests bs4
pip install requests
- name: Update language files
run: |
Expand Down
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def table() -> str:
tzinfo = get_timezone(session["timezone"])
date_tz = datetime.now(tz=tzinfo).date()

return render_template("table.html", date_str=date_tz)
return render_template("table.html", date_str=date_tz, data=data)


QUESTION_AMOUNT = 10 # 测验题组含题目数量
Expand Down
67 changes: 0 additions & 67 deletions table.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,80 +3,13 @@

import csv

from bs4 import BeautifulSoup

from app_base import P, language_list
from app_init import data

HTML_TEMPLATE = """<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Translation Table</title>
<link rel="icon" href="{{ url_for('static', filename='favicon.ico') }}">
<link rel="apple-touch-icon" href="{{ url_for('static', filename='images/apple-touch-icon.png') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='css/table.css') }}" type="text/css">
<link rel="stylesheet" href="https://fonts.font.im/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@24,400,0,0" />
</head>
<body>
<div class="header">
Minecraft Standard Translation Table. Latest Update: {{ date_str }}<br>Made by SkyEye_FAST.&emsp;
<a href="../"><span class="material-symbols-outlined b">manage_search</span>Query Page</a>&emsp;
<a class="github-link" href="https://github.com/SkyEye-FAST/minecraft_translation_flask">
<img class="github-icon" src="{{ url_for('static', filename='images/github-icon.svg') }}" alt="GitHub">
GitHub
</a>&emsp;
<a href="../table.tsv"><span class="material-symbols-outlined b">download</span>Download TSV</a>
</div>
<table>
<thead>
<tr>
<th>keys</th>
<th>en_us</th>
<th>zh_cn</th>
<th>zh_hk</th>
<th>zh_tw</th>
<th>lzh</th>
<th>ja_jp</th>
<th>ko_kr</th>
<th>vi_vn</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</body>
</html>
"""


def main() -> None:
"""主函数"""

soup = BeautifulSoup(HTML_TEMPLATE, "html.parser")
tbody = soup.find("tbody")

for key in data["en_us"]:
new_row = soup.new_tag("tr")
key_cell = soup.new_tag("td")
key_cell.string = key
new_row.append(key_cell)

for lang_data in data.values():
value = lang_data.get(key, "?")
new_cell = soup.new_tag("td")
new_cell.string = value
new_row.append(new_cell)

tbody.append(new_row)

with open(P / "templates" / "table.html", "w", encoding="utf-8") as f:
f.write(str(soup))

with open(P / "static" / "table.tsv", "w", encoding="utf-8", newline="") as f:
writer = csv.writer(f, delimiter="\t")
headers = ["key"] + language_list
Expand Down
87 changes: 54 additions & 33 deletions templates/table.html

Large diffs are not rendered by default.

0 comments on commit 0948c01

Please sign in to comment.