I m writing command line script in python to execute my scala code. but I m struct in formating the input json with List.
see below some part of python script:
CONTEXT_SETTINGS = """
{
"CustomerTable": {
"table": "%s",
"host" : "localhost",
"customerList" : %s
}
}
"""
class CmdLineParser():
def __init__(self, description):
self.parser = argparse.ArgumentParser(
description=description)
self.add_argument('-v', '--verbose', default=False,
action='store_true',
help='Verbose mode')
self.add_argument('-t', '--table', nargs='?',
help='my table', required=True)
def add_argument(self, *args, **kwargs):
self.parser.add_argument(*args, **kwargs)
def get_ctx_config(self, cust_sub_ids):
args = self.parser.parse_args()
context_dict = json.loads(
CONTEXT_SETTINGS % (args.table, customerids))
return context_dict
how to load json file to set the customerids. where customerids = ['1234', '2345', '5678' .....] and get_ctx_config is call from main file.
so that input json file should become
{
"CustomerTable": {
"table": "mytable",
"host" : "localhost",
"customerList" : ["1234", 2345", "5678"]
}
}
and context_dic return should like:
u'CustomerTable': {u'table': u'mytable', u'host': u'localhost', u'cust_sub_id': [u'1234', u'1235', u'1236', u'1237', u'1234']}
how to write python script to update the.
context_dict = json.loads(
CONTEXT_SETTINGS % (args.table, customerids))
and what will be needed to set type for list in CONTEXT_SETTING like %s for String.