benten download_zip_file

目的

  • donwload_zipで生成したZIPファイルをダウンロードします。

Warning

事前にログイン認証を行う必要があります。

Warning

システム負荷軽減のため、一度に2GB以上のファイルをダウンロードすることは禁止しています。

利用例

  • Help
$ benten.py download_zip_file -h
usage: benten download_zip_file [-h] [--flag_unzip]
                                [--out_directory [OUT_DIRECTORY]]
                                [--disable_hash]
                                uuid

positional arguments:
  uuid                  uuid for download

optional arguments:
  -h, --help            show this help message and exit
  --flag_unzip, -u      unzip file if the file is available
  --out_directory [OUT_DIRECTORY], -d [OUT_DIRECTORY]
                        directory for output file if the file is available
  --disable_hash        disable hash check in downloaded file
  • download_zipでダウンロード命令を実行し、download_zip_queue で statusを確認した後に、ZIPファイルをダウンロード
$ benten.py download_zip -r "/SPring-8/BL14B2/test/test"

### benten download_zip ###
[Repository::authorize] access_token = 579773811dc7401ea1307c99d2a88a82
==> response
{
    "status":"STARTED",
    "uuid":"9e0f079e-13ed-49e2-873b-2f48fdfe9222"
}

$ benten.py download_zip_queue 9e0f079e-13ed-49e2-873b-2f48fdfe9222
### benten download_zip_queue ###
==> response
{
    "file_list":[
        {
            "size":44,
            "name":"/SPring-8/BL14B2/test/test.json",
            "time":"2018-08-15 18:14:05",
            "hash":"4cdb2c555c08a9d787a2e61103dff0f8",
            "uuid_name":"9e28d9d3-f3e9-441b-b9f2-152e68c310a9"
        },
        {
            "size":425,
            "name":"/SPring-8/BL14B2/test/test.system.json",
            "time":"2019-03-09 21:18:35",
            "hash":"49b71db137ce7da3b8ce26f62f643722",
            "uuid_name":"933c7d86-94f7-448f-8f37-7199d64acca9"
        }
    ],
    "status":"SUCCESS",
    "uuid":"9e0f079e-13ed-49e2-873b-2f48fdfe9222"
}

$ benten.py download_zip_file 9e0f079e-13ed-49e2-873b-2f48fdfe9222
### benten download_zip_file ###
[Repository::authorize] access_token = 579773811dc7401ea1307c99d2a88a82
==> downloaded with file = 9e0f079e-13ed-49e2-873b-2f48fdfe9222.zip

Pythonモジュールとの対応

#!/usr/bin/env python
'''
  example: download_zip_file

  usage: python benten_download_zip_file.py [uuid]

'''

import benten_client

import time

import argparse
from logging import getLogger, StreamHandler, DEBUG
logger = getLogger(__name__)
handler = StreamHandler()
handler.setLevel(DEBUG)
logger.setLevel(DEBUG)
logger.addHandler(handler)
logger.propagate = False

# ... parameters
parser = argparse.ArgumentParser(description="example: download_zip_file")
parser.add_argument("uuid", help="uuid for download")
parser.add_argument("--flag_unzip", "-u", action="store_const",
                    const=1, help="unzip file if the file is available")
parser.add_argument("--out_directory", "-d", nargs="?",
                    help="directory for output file if the file is available")

args = parser.parse_args()

uuid_file = args.uuid
flag_unzip = args.flag_unzip
out_directory = args.out_directory

repo = benten_client.Repository() 

logger.debug("# set access token")

repo.authorize(benten_client.access_token())

logger.debug("# download_zip_file")

ret_dict = repo.download.file.get(
    uuid_file, out_directory=out_directory, unzip=flag_unzip)
if ret_dict is not None:
    benten_client.log("==> response")
    benten_client.out_json(ret_dict)