benten proposal_meta

目的

  • 課題番号に紐づくメタデータを参照します。

Warning

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

概要

  • 認証時のアカウントでアクセスできる課題番号である時に、課題番号に関連したメタデータを課題DBから取得します。

利用例

  • Help
$ benten.py proposal_metadata -h
usage: benten proposal_metadata [-h]
                                [--proposal_number [PROPOSAL_NUMBER]]
                                [--facility [FACILITY]]

optional arguments:
  -h, --help            show this help message and exit
  --proposal_number [PROPOSAL_NUMBER], -p [PROPOSAL_NUMBER]
                        proposal_number
  --facility [FACILITY], -f [FACILITY]
                        facility
  • 課題番号に紐づくメタデータ取得
$ benten.py proposal_metadata -p 2014S0000
### benten proposal_metadata ###
[Repository::authorize] access_token = 78fb9b529fcc4fbdb6ae2884664f2ba8
==> response
{
    "found":true,
    "metadata":{
        "@data_info@facility":"SPring-8",
        "@data_info@class_name":"BL14B2",
        "@data_info@title_ja":"標準試料",
        "@data_info@title":"Standard Sample",
        "@data_info@identifier@proposal_number":"2014S0000",
        "@data_info@contact_name@name":"Hironori Ofuchi",
        "@data_info@contact_name@affiliation@organization":"(公財)高輝度光科学研究センター",
        "@data_info@contact_name@role":"person",
        "@data_info@contact_name@identifier@name":"0007719"
    }
}

Pythonモジュールとの対応

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

  usage: python benten_proposal_meta.py ...

'''

import benten_client

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: proposal_meta")
parser.add_argument("--proposal_number", "-p",
                 nargs="?", help="proposal_number")
parser.add_argument("--facility", "-f", nargs="?", help="facility")

args = parser.parse_args()

proposal_number = args.proposal_number
facility = args.facility

v = {}
if proposal_number is not None:
    v["proposal_number"] = proposal_number
if facility is not None:
    v["facility"] = facility

repo = benten_client.Repository() 

logger.debug("# set access token")

repo.authorize(benten_client.access_token())

logger.debug("# benten proposal_meta")

ret_dict = repo.proposal.metadata.post(**v)

benten_client.log("==> response")
benten_client.out_json(ret_dict)