Skip to content

Commit

Permalink
Update stardict.7z - refashed 12365 tag and 160,435 uk us phonetic
Browse files Browse the repository at this point in the history
- tag.ddb  从 qwerty-learner 收集整理的标签数据库
- phonetics.ddb 从精装牛津十爬取得到的英美音标数据库
  • Loading branch information
H1DDENADM1N committed Jan 13, 2025
1 parent a534cf4 commit 7a83e99
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 6 deletions.
25 changes: 19 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
__pycache__
# 忽略 Python 缓存目录
__pycache__/

/.vscode/*
# 忽略 VSCode 配置目录
/.vscode/
/.history/

# 忽略特定文件
writemdict
.history
stardict.csv
stardict.ddb
stardict.txt
concise-enhanced.mdx
concise-enhanced.png
concise-enhanced.css
Secret.py

# 忽略 output 目录下的所有文件,除了 tag.ddb 和 phonetics.ddb
/output/*
/logs/*
/oald-fork/*
qwerty-learner/
!output/tag.ddb
!output/phonetics.ddb

# 忽略 logs 目录
/logs/

# 忽略 oald-fork 目录
/oald-fork/

# 忽略 qwerty-learner 目录
/qwerty-learner/
43 changes: 43 additions & 0 deletions ddb_to_csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from datetime import datetime
from pathlib import Path

import duckdb
from loguru import logger


def convert_stardictdb_to_csv(stardictdb_file: Path, csv_file: Path) -> None:
"""
将 stardict.ddb 数据库转换回 stardict.csv 文件。
:param stardictdb_file: DuckDB 数据库文件路径
:param csv_file: 目标 CSV 文件路径
:raises FileNotFoundError: 如果 stardictdb_file 不存在
"""
# 检查输入文件是否存在
if not stardictdb_file.exists():
logger.error(f"数据库文件 {stardictdb_file} 未找到")
raise FileNotFoundError(f"数据库文件 {stardictdb_file} 未找到")

# 处理目标文件已存在的情况
if csv_file.exists():
current_time = datetime.now().strftime("%Y%m%d_%H%M%S")
new_name = csv_file.with_name(f"stardict_old_{current_time}.csv")
csv_file.rename(new_name)
logger.info(f"已存在的 {csv_file} 已重命名为 {new_name}")

try:
# 连接到 DuckDB 数据库(只读模式)
with duckdb.connect(database=str(stardictdb_file), read_only=True) as conn:
# 导出数据到 CSV 文件
conn.execute(f"COPY stardict TO '{csv_file}' (FORMAT CSV, HEADER)")
logger.info(f"成功将 {stardictdb_file} 导出为 {csv_file}")
except Exception as e:
logger.error(f"导出过程中发生错误: {e}")
raise


if __name__ == "__main__":
output_dir = Path("output")
stardictdb_file = Path() / output_dir / "stardict.ddb"
stardict_csv = Path() / "stardict.csv"
convert_stardictdb_to_csv(stardictdb_file, stardict_csv)
Binary file added output/phonetics.ddb
Binary file not shown.
Binary file added output/tag.ddb
Binary file not shown.
Binary file modified stardict.7z
Binary file not shown.

0 comments on commit 7a83e99

Please sign in to comment.