forked from skywind3000/ECDICT
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update stardict.7z - refashed 12365 tag and 160,435 uk us phonetic
- tag.ddb 从 qwerty-learner 收集整理的标签数据库 - phonetics.ddb 从精装牛津十爬取得到的英美音标数据库
- Loading branch information
1 parent
a534cf4
commit 7a83e99
Showing
5 changed files
with
62 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.
Binary file not shown.
Binary file not shown.