Skip to main content

retrieve data from centralSystem.org

Project description

simplify data retrieving on centralSystem.org

download file

import central_system
from central_system import Client, ApiRequest, Method

c = Client(data_endpoint="",access_key="", secret_key="",authorized_endpoint="")
api_request = ApiRequest(data_address="1754C67BE4821000", request_path="api-provider/download/local/123456",
                                 method=Method.POST)
try:
    # 模式一
    r = c.call_api(api_request)
    with open('./img8.jpg', 'wb') as f:
        f.write(r.content)

    # 模式二
    f = open('./img5.jpg', 'wb')
    response_stream = c.call_api_stream(api_request)
    with response_stream as r:
        for chunk in r.iter_bytes(chunk_size=4096):
            f.write(chunk)
finally:
    f.close()

do http

import central_system
from central_system import Client, ApiRequest, Method

c = Client(data_endpoint="",access_key="", secret_key="",authorized_endpoint="")

params = {'pkey1': 'value1', 'pkey2': 'value2'}
json = {'jkey1': 'value1', 'jkey2': 'value2'}
headers = {'user-agent': 'my-app/0.0.1'}
api_request = ApiRequest(data_address="178589E198821000", request_path="post",
                         method=Method.POST, headers=headers, params=params, json=json, timeout=10)
response = c.call_api(api_request)
print(response.content)

do pgsql

import central_system
from central_system import Client, ApiRequest, Method

c = Client(data_endpoint="",access_key="", secret_key="",authorized_endpoint="")
json = {"payload": "{ \"sql\": \"select * from zs.student\" }"}
api_request = ApiRequest(data_address="1785CB2070C21000", request_path="pg",
                         method=Method.POST, json=json, timeout=10)
response = c.call_api(api_request)
print(response.content)

do odps

import logging
import central_system
from central_system import Client, ApiRequest, Method

c = Client(data_endpoint="",access_key="", secret_key="",authorized_endpoint="")

json = {"payload": "{ \"selectSql\": \"select * from user \" }"}
api_request = ApiRequest(data_address="174FB94000C21000", request_path="get/odps",
                         method=Method.POST, json=json, timeout=10)
response = c.call_api(api_request)
print(response.content)

enable log

import logging
import central_system

central_system.set_file_logger("../log/central.log", level=logging.DEBUG)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

central_system-1.0.2.tar.gz (5.2 kB view hashes)

Uploaded Source

Built Distribution

central_system-1.0.2-py3-none-any.whl (6.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page