Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ following command:

python -m unidic download

Additionally you can specify custom version and URL arguments demonstrated as such:

python -m unidic download "3.1.0+2021-08-31" "https://cotonoha-dic.s3-ap-northeast-1.amazonaws.com/unidic-3.1.0.zip"

With [fugashi](https://github.com/polm/fugashi) or
[mecab-python3](https://github.com/samurait/mecab-python3) unidic will be used
automatically when installed, though if you want you can manually pass the
Expand Down
35 changes: 22 additions & 13 deletions unidic/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,26 @@ def download_and_clean(version, url, dirname='unidic', delfiles=[]):

DICT_INFO = "https://raw.githubusercontent.com/polm/unidic-py/master/dicts.json"

def download_version(ver="latest"):
res = get_json(DICT_INFO, "dictionary info")
try:
dictinfo = res[ver]
except KeyError:
print('Unknown version "{}".'.format(ver))
print("Known versions:")
for key, val in res.items():
print("\t", key, "({})".format(val['version']))

print("download url:", dictinfo['url'])
print("Dictionary version:", dictinfo['version'])
download_and_clean(dictinfo['version'], dictinfo['url'])
def download_version(ver="latest", url:str=""):
if len(url) > 0:
print('Custom download params: url="{}"; ver="{}".'.format(url, ver))
try:
res = get_json(DICT_INFO, "dictionary info")
dictinfo = res[ver]
ver = dictinfo['version']
finally:
download_and_clean(ver, url)
else:
res = get_json(DICT_INFO, "dictionary info")
try:
dictinfo = res[ver]
except KeyError:
print('Unknown version "{}".'.format(ver))
print("Known versions:")
for key, val in res.items():
print("\t", key, "({})".format(val['version']))

print("download url:", dictinfo['url'])
print("Dictionary version:", dictinfo['version'])
download_and_clean(dictinfo['version'], dictinfo['url'])