Skip to content

5. ローダ作成プログラム例(WebAPI)

以下にローダプログラム作成例を示します。

・sample_loader.py

# coding:utf-8  
import api_common  
import loader_api  
import requests

'''  
Load sample loader  
'''
def sample_loader():

    # Initial setting  
    ini_info = api_common.init_setting()

    # Register loader parameter setting  
    data_name = ini_info['WEB_API']['data_name']  
    options = ini_info['WEB_API']['options']

    # Collect data  
    # (loader specific data get)

    # 1 record  
    one_record_dic = {}
    one_record_dic['location'] = {}
    one_record_dic['start_datetime'] = '2019-09-13 00:00:00+09'  
    one_record_dic['end_datetime'] = '2019-09-13 00:30:00+09'  
    one_record_dic['city'] = 'tokyo'  
    one_record_dic['co2'] = '1.23'  
    one_record_dic['location']['type'] = "Point"
    one_record_dic['location']['coordinates'] = [139.6, 35.6]
    record_list.append(one_record_dic)

    # 2 record  
    one_record_dic['start_datetime'] = '2019-09-14 00:00:00+09'
    one_record_dic['end_datetime'] = '2019-09-14 00:30:00+09'
    one_record_dic['city'] = 'chiba'
    one_record_dic['co2'] = '2.34'
    one_record_dic['location']['type'] = "Point"
    one_record_dic['location']['coordinates'] = [139.6, 35.6]
    record_list.append(one_record_dic)

    # Initialize record  
    record_size = len(record_list)
    res_init_json = loader_api.init_record(data_name, record_size)

    # Add record  
    response_api = loader_api.add_record(record_list, res_init_json, data_name, options)

    return

'''  
main function  
'''  
if __name__ == '__main__':

    # Load sample_loader  
    sample_loader()

・common.ini

[WEB_API]
data_name = sample_table
options = override


戻る