UNIHAN数据库的SQLAlchemy模型
unihan-db的Python项目详细描述
unihan db-数据库SQLAlchemy模型,用于UNIHAN。cihai的一部分 项目。{a4}驱动。另请参见:libUnihan。在
默认情况下,unihan db在XDG data directory中创建一个SQLite数据库。 可以通过传递数据库url来指定自定义数据库目标 进入get_session。在
示例用法
#!/usr/bin/env python# -*- coding: utf8 - *-from__future__importunicode_literalsimportpprintfromsqlalchemy.sql.expressionimportfuncfromunihan_dbimportbootstrapfromunihan_db.tablesimportUnhnsession=bootstrap.get_session()bootstrap.bootstrap_unihan(session)random_row=session.query(Unhn).order_by(func.random()).limit(1).first()pp=pprint.PrettyPrinter(indent=0)pp.pprint(random_row.to_dict())
运行:
^{pr2}$输出:
{'char':'鎷','kCantonese':[{'char_id':'鎷','definition':'maa5','id':24035}],'kDefinition':[],'kHanYu':[{'char_id':'鎷','id':24014,'locations':[{'character':5,'generic_indice_id':24014,'generic_reading_id':None,'id':42170,'page':4237,'virtual':0,'volume':6}],'type':'kHanYu'}],'kHanyuPinyin':[{'char_id':'鎷','id':18090,'locations':[{'character':5,'generic_indice_id':None,'generic_reading_id':18090,'id':42169,'page':4237,'virtual':0,'volume':6}],'readings':[{'generic_reading_id':18090,'id':26695,'reading':'mǎ'}],'type':'kHanyuPinyin'}],'kMandarin':[{'char_id':'鎷','hans':'mǎ','hant':'mǎ','id':23486}],'ucn':'U+93B7'}
发展中
poetry是开发所需的包。在
git clone https://github.com/cihai/unihan-etl.git
cd unihan-etl
poetry install -E "docs test coverage lint format"
以watch_为前缀的Makefile命令将监视文件并重新运行。在
文档
默认预览服务器:http://localhost:8041
生成cd docs/和make html。make serve启动http服务器。在
帮助者: make build_docs,make serve_docs
在文件更改时重新生成文档:make watch_docs(需要entr(1))
重新生成文档并通过一个终端运行服务器:make dev_docs(需要上述内容,以及 make(1),支持-J,例如gnumake)
格式化/Linting
项目使用black和{a17}(一个接一个),并通过运行flake8 CI。请参阅中的配置pyproject.toml项目和设置.cfg:
make black isort:首先运行black,然后运行isort,以处理导入的细微差别 make flake8,要观看(需要entr(1)):make watch_flake8
释放
从0.11开始,poetry处理virtualenv创建、包要求、版本控制, 建筑和出版。因此没有设置.py或需求文件。在
在中更新中的版本pyproject.toml项目:
git commit -m 'build(unihan-db): Tag v0.1.1' git tag v0.1.1 git push git push --tags poetry build poetry deploy
- 项目
标签: