Package: kanjidb
KanjiDBKanji database builder and REST API.KanjiDB aims to help you build your own kanji database by compiling
informations from various existing source into a single JSON file.
It's plugin system let you write you own plugin to collect and add new data to kanjis,
or to arrange already written plugins to meet your needs. It's goal
is to be flexible enough to let you export all the informations you
need to build your own app (database, viewer, Anki deck builder, ...) and
progress in learning Japanese. KanjiDB also comes with a REST API allowing to
retrieve those informations and build services uppon.Online demoYou can test the REST API online atkanjidb.jeremymorosi.com/api/v1/doc:The documentation is generated byaiohttp_swagger.InstallUsing pip:pipinstallkanjidbShow help:python-mkanjidb-h

Usage:kanjidbCOMMAND[OPTIONS]AkanjidatabaseaccessibleviaRESTAPI

Options:-v,--versionPrintversioninformationandquit-h,--helpShowthishelpCommands:buildBuildkanjidatabasefromsourcesrunRunlocalserverandRESTAPI

Run'kanjidb COMMAND --help'formoreinformationonacommand.Generating a JSON databaseCreate akanjis.txtfile containing one UTF-8 encoded kanji per line. This is the list of kanjis
that will be included in our database:ä¸€
äºŒ
ä¸‰Now, create aconfig.ymlfile containing:run:-kanjidic2:kd2_file:path/to/kanjidic2.xmlinputs:-type:streamencoding:utf8separator:"\n"path:path/to/kanjis.txtoutputs:-type:streamindent:4path:path/to/db.jsonIn this configuration:kanjistream: is a plugin that generate a JSON dict with data from a Kanjidic2 XML file.path/to/kanjidic2.xml: is the path to a Kanjidic2 XML file (download here).path/to/kanjis.txt: is the path to thekanjis.txtfile.path/to/db.json: is the destination of generated JSON database.Run the following command:python-mkanjidbbuildconfig.ymlThis generate adb.jsonfile containing the generated JSON database.
Depending on your configuration this file can be quite big, so here is only an example of what you
would obtain:{"ä¸€":{"meanings":[{"m_lang":"","value":"one"}]},"äºŒ":{"meanings":[{"m_lang":"","value":"two"}]},"ä¸‰":{"meanings":[{"m_lang":"","value":"three"}]}}You can read more about thekanjidic2plugin and its configurationhere.Running the REST APINow we will run a local server with a REST API allowing us to query informations from generateddb.jsonfile.First, create aconfig.cnffile containing:[service]port=8080base-url=/api/v1swagger-yml=/path/to/swagger.ymlswagger-url=/api/v1/docdb-file=/path/to/db.jsonJust replace:/path/to/swagger.yml: by the path to your localswagger.ymlfile./path/to/db.json: by the path to your generateddb.jsonfile.Now run:python-mkanjidbrun/path/to/config.cnf/directory/You should see:========Runningonhttp://0.0.0.0:8080========(PressCTRL+Ctoquit)Meaning the service is up and ready.You can access it via:http://127.0.0.1:8080/api/v1/doc: Swagger documentationhttp://127.0.0.1:8080/api/v1/kanji: list all kanjis in database.Note that this repository also include a defaultconfig.cnf,swagger.ymlanddb.jsonfile you can use to run the server. Simply checkout this repository and run:python-mkanjidbrunetcRunning with DockerYou can build a Docker image by downloading this repository and running:dockerbuild-tkanjidb:latest.Next, run the Docker image as:dockerrun\-v/path/to/etc:/etc/service\-v/path/to/log:/var/log/service\-p8080:8080\-itkanjidb:latestWhere:/path/to/etc: is the path to the service directory containingconfig.cnf./path/to/log: is the path to the directory where you wan't to store logs.8080: is the public port to access the REST API.You should see:========Runningonhttp://0.0.0.0:8080========(PressCTRL+Ctoquit)Meaning the service is up and ready.TestingThetestdirectory contains many tests that you can run with:pythonsetup.pytestOr with coverage:coveragerun--source=kanjidbsetup.pytest