鹏程万里----阿里云服务器获取数据

try:
    client = OTSClient("https://hps.cn-hongkong.ots.aliyuncs.com", "LTAI4FzfwqVieWN7i1BeXNKQ",
                       "qBRQrEM69eHIn9kzQDBrufmLZcx8", "hps")
    inclusive_start_primary_key = [('sn', "S65000A119702023"), ('time', '2020-01-20 00:00:02')]
    exclusive_end_primary_key = [('sn', "S65000A119702023"), ('time', '2020-01-20 23:59:59')]
    columns_to_get = []
    limit = 1000
    consumed, next_start_primary_key, row_list, next_token = client.get_range(
        'device_workdata', Direction.FORWARD,
        inclusive_start_primary_key, exclusive_end_primary_key,
        columns_to_get,
        limit,
        max_version=1
    )

    all_rows = []
    all_rows.extend(row_list)
    while next_start_primary_key is not None:
        inclusive_start_primary_key = next_start_primary_key
        consumed, next_start_primary_key, row_list, next_token = client.get_range(
            'device_workdata', Direction.FORWARD,
            inclusive_start_primary_key, exclusive_end_primary_key,
            columns_to_get, limit,
            max_version=1
        )
        all_rows.extend(row_list)
        print('Read succeed, consume %s read cu.' % consumed.read)

    for row in all_rows:
        print(row.primary_key, row.attribute_columns)
    print('Total rows: ', len(all_rows))
except Exception as err:
    print(err)

从阿里云数据服务器上获取数据的例子

你可能感兴趣的:(鹏程万里----阿里云服务器获取数据)