Example #1
0
async def init(loop):
    # Load configuration file
    config = load_config(PROJECT_ROOT / 'config' / 'config.yml')

    # Connect to Cassandra cluster
    cluster = Cluster(
        [config["cassandra"]["host"]],
        load_balancing_policy=DCAwareRoundRobinPolicy(),
        port=config["cassandra"]["port"])
    session = cluster.connect()

    # Set keyspace
    session.set_keyspace(config["cassandra"]["keyspace"])

    # Threaded Cassandra wrapper for asyncio
    aiosession(session)

    # Setup database store
    db_store = DbStore(session, config)

    # Setup server application
    app = web.Application(loop=loop)
    handler = RoutesHandler(db_store, config)
    register_routes(app, handler)
    host, port = config["api"]["host"], config["api"]["port"]

    return app, host, port
Example #2
0
 def _check_args(self):
     public_key, private_key, resource_id = load_config(self.config_file)
     if public_key == '':
         raise ValueError("Current config file: {0} invalid, public_key is empty".
                          format(self.config_file))
     if private_key == '':
         raise ValueError("Current config file: {0} invalid, private_key is empty".
                          format(self.config_file))
     if resource_id == '':
         raise ValueError("Current config file: {0} invalid, resource_id is empty".
                          format(self.config_file))
Example #3
0
import sys
import time
from api.utils import load_config, gen_signature
from api.ocr_bill_job import UAIOcrBillJobApi

if __name__ == '__main__':
    if len(sys.argv) == 2:
        config_file = sys.argv[1]
    else:
        config_file = '../config_files/bill-config-online.json'

    url = 'http://uai-demo-adam.cn-bj.ufileos.com/bill.jpg'
    timestamp = int(time.time())
    public_key, private_key, resource_id = load_config(config_file)
    signature = gen_signature(config_file=config_file,
                              timestamp=timestamp,
                              url=url)

    caller = UAIOcrBillJobApi(signature=signature,
                              public_key=public_key,
                              resource_id=resource_id,
                              timestamp=timestamp,
                              method='url',
                              url=url)
    caller.call_api()
import sys
from api.create_censor_resource import CreateUAICensorResourceApi
from api.utils import load_config

# usage: python create_async_toframe_job.py config_file='toframe-config.json'

if __name__ == '__main__':
    if len(sys.argv) == 2:
        config_file = sys.argv[1]
    else:
        config_file = '../config_files/controller-config-pre.json'

    resource_types = '0'
    public_key, private_key, _ = load_config(config_file)
    caller = CreateUAICensorResourceApi(public_key, private_key, resource_types)
    caller.call_api()