Exemple #1
0
def run_async():
    print("async example")
    print("=============")

    result = []

    def handle_future(future):
        result.extend(future.result())

    loop = asyncio.get_event_loop()

    transport = AsyncTransport(loop, cache=None)
    client = zeep.Client('http://localhost:8000/?wsdl', transport=transport)

    tasks = [
        client.service.slow_request('request-1'),  # takes 1 sec
        client.service.slow_request('request-2'),  # takes 1 sec
    ]
    future = asyncio.gather(*tasks, return_exceptions=True)

    result = []
    future.add_done_callback(handle_future)

    st = time.time()
    loop.run_until_complete(future)
    loop.run_until_complete(transport.session.close())
    print("time: %.2f" % (time.time() - st))
    print("result: %s", result)
    print("")
    return result
    def __init__(self, hass, config):
        """Initialize an ONVIF camera."""
        super().__init__()

        _LOGGER.debug("Importing dependencies")

        _LOGGER.debug("Setting up the ONVIF camera component")

        self._username = config.get(CONF_USERNAME)
        self._password = config.get(CONF_PASSWORD)
        self._host = config.get(CONF_HOST)
        self._port = config.get(CONF_PORT)
        self._name = config.get(CONF_NAME)
        self._ffmpeg_arguments = config.get(CONF_EXTRA_ARGUMENTS)
        self._profile_index = config.get(CONF_PROFILE)
        self._ptz_service = None
        self._input = None
        self._snapshot = None
        self.stream_options[CONF_RTSP_TRANSPORT] = config.get(
            CONF_RTSP_TRANSPORT)
        self._mac = None

        _LOGGER.debug("Setting up the ONVIF camera device @ '%s:%s'",
                      self._host, self._port)

        session = async_get_clientsession(hass)
        transport = AsyncTransport(None, session=session)
        self._camera = ONVIFCamera(
            self._host,
            self._port,
            self._username,
            self._password,
            "{}/wsdl/".format(os.path.dirname(onvif.__file__)),
            transport=transport,
        )
Exemple #3
0
def run(port, wsdl, device_id, password, debug):
    transport = AsyncTransport(asyncio.get_event_loop(), cache=None)
    client = zeep.Client(wsdl, transport=transport)

    app = make_app(device_id, password, debug, client)
    app.listen(port)
    ioloop.IOLoop.current().start()
Exemple #4
0
async def main():
    st = time()
    loop = asyncio.get_event_loop()
    load_dotenv()

    # Load Environmental Variable
    wsdl = os.getenv("WSDL_FILE")
    username = os.getenv("UCM_USERNAME")
    password = os.getenv("UCM_PASSWORD")
    ucm_pub_url = f'https://{os.getenv("UCM_PUB_ADDRESS")}:8443/axl/'

    print(f"init: {time() - st}s")

    # Create Session, do not verify certificate, enable basic auth
    # ISSUE, zeep not using cookies, authenticating every time
    # authentication is rate limited
    connector = TCPConnector(ssl=False, limit=5)
    auth = BasicAuth(username, password)
    async with ClientSession(connector=connector, auth=auth) as session:
        transport = AsyncTransport(loop=loop, session=session, timeout=10)
        client = Client(wsdl, transport=transport)

        # create the service proxy pointint to our UCM
        service = client.create_service(
            binding_name="{http://www.cisco.com/AXLAPIService/}AXLAPIBinding",
            address=ucm_pub_url,
        )
        print(f"Zeep Setup: {time() - st}s")
        phone_list = await get_phone_list(service)
        # print(client.transport.session)
        print(f"phone List: {time() - st}s")
        await get_phone_list_detail(service, phone_list)
        print(f"Done: {time() - st}s")
Exemple #5
0
    def __init__(self, settings, ip=None, client=None):
        from zeep.asyncio import AsyncTransport

        self.client = client or Client(
            settings["PAYTPVWSDL"],
            transport=AsyncTransport(loop=asyncio.get_event_loop()),
        )
        self.builder = RequestBuilder(settings, ip)
Exemple #6
0
async def soap_request(request, key):
    year, mnr, c_number = key
    future = requested_keys.get(key)
    if future is None:
        future = requested_keys[key] = Future()
        transport = AsyncTransport(request.app.loop, cache=None)
        client = Client(request.app.config.soap_service, transport=transport)
        result = await client.service.getLNRecherche(c_number, mnr, year)
        future.set_result(result)
    return future
def get_device(hass, host, port, username, password) -> ONVIFCamera:
    """Get ONVIFCamera instance."""
    session = async_get_clientsession(hass)
    transport = AsyncTransport(None, session=session)
    return ONVIFCamera(
        host,
        port,
        username,
        password,
        f"{os.path.dirname(onvif.__file__)}/wsdl/",
        transport=transport,
    )
Exemple #8
0
 def __init__(self, xml_string="", endpoint=api.SCHEDULE_ENDPOINT):
     """
     Async is actually slower than regular with Tangier. Don't use.
     :param xml_string: override the default xml, which is just <tangier method="schedule.request"/>
     :param endpoint: where the WSDL info is with routing info and SOAP API definitions
     """
     super(self.__class__, self).__init__()
     if not xml_string:
         self.base_xml = """<tangier version="1.0" method="schedule.request"></tangier>"""
     else:
         self.base_xml = xml_string
     self.base_xml = xmlmanip.inject_tags(self.base_xml,
                                          user_name=api.TANGIER_USERNAME,
                                          user_pwd=api.TANGIER_PASSWORD)
     self.loop = asyncio.get_event_loop()
     self.transport = AsyncTransport(self.loop, cache=None)
     self.client = Client(endpoint, transport=self.transport)
     self.good_responses = []
     self.bad_responses = []
Exemple #9
0
    def makeRequest(self, func, data):
        result = []

        def handle_future(future):
            result.extend(future.result())

        loop = asyncio.get_event_loop()

        transport = AsyncTransport(loop, cache=None)
        client = zeep.Client(self.PATH, transport=transport)

        tasks = [getattr(client.service, func)(**data)]
        future = asyncio.gather(*tasks, return_exceptions=True)

        future.add_done_callback(handle_future)

        # st = time.time()
        loop.run_until_complete(future)
        loop.run_until_complete(transport.session.close())
        # print("time: %.2f" % (time.time() - st))
        return result
Exemple #10
0
    def __init__(self,
                 xaddr,
                 wsse: UsernameDigestTokenDtDiff,
                 url: Path,
                 *,
                 bindingName='',
                 transport=None):
        if not url.is_file():
            raise ONVIFError('%s doesn`t exist!' % url)

        self.url = url
        self.xaddr = xaddr

        if not transport:
            transport = AsyncTransport(None)
        self.client = Client(wsdl=str(url),
                             wsse=wsse,
                             transport=transport,
                             settings=Settings(strict=False,
                                               xml_huge_tree=True))
        self.wsClient = self.client.create_service(bindingName, xaddr)
        self.bindingName = bindingName
# logging.basicConfig(level=logging.DEBUG)

RCW_GETDATA_VALUE_COUNT = 3000
WSDL = 'wsdl/RcWareDbAccess.wsdl'

MAX_CONCURRENCY = 2

loop = asyncio.get_event_loop()
loop.set_debug(False)

settings = zeep.Settings(strict=True,
                         xml_huge_tree=True,
                         force_https=False,
                         raw_response=False)
transport = AsyncTransport(loop)
# Available ports are HistoryAccess, HistoryAccessGZip, HistoryAccess1. Only HistoryAccess seems to be alive.
client = zeep.Client(wsdl=WSDL,
                     settings=settings,
                     port_name='HistoryAccess',
                     transport=transport)
factory = client.type_factory(
    'http://schemas.datacontract.org/2004/07/ESG.Db.Server.Shared')

creds = factory.Credentials(Name=username, Password=password)
influxdb = InfluxDBClient('influxdb.power-hash.com', port=80)


def load_mapping(filename):
    measurements_map = {}
    influx_keys = ('plant', 'device_type', 'device', 'measurement', 'via')
Exemple #12
0
def run_async():
    print("async example")
    print("=============")

    result = []

    def handle_future(future):
        result.extend(future.result())
        print(future.result())

    loop = asyncio.get_event_loop()
    wsdl = 'http://10.21.2.75:8080/service/LBEBusiness?wsdl'
    transport = AsyncTransport(loop, cache=None)
    client = zeep.Client(wsdl, transport=transport)
    # login_ans = client.service.login("ZXQH_GPXZ", "GPXZ123321", "myapp", "plain", ""),
    # sessionId = login_ans[0].sessionId
    lbParameter_type = client.get_type('ns0:lbParameter')
    queryOption_type = client.get_type('ns0:queryOption')
    par_dict = {
        "KSRQ": "2018-11-13",
        "JSRQ": "2018-11-13",
        "YYB": "1",
        # "TJFL": "0",
        "TJFL": "1",
    }
    params = []
    for key in par_dict:
        val = par_dict[key]
        temp_lbParameter = lbParameter_type(name=key, value=val)
        params.append(temp_lbParameter)
    valueOption_type = client.get_type('ns0:valueOption')
    valueOption = valueOption_type('VALUE')
    batchNo = 1
    batchSize = 30
    mqueryOption = queryOption_type(batchNo=batchNo,
                                    batchSize=batchSize,
                                    queryCount=True,
                                    valueOption=valueOption)
    batchNo += 1
    mqueryOption2 = queryOption_type(batchNo=batchNo,
                                     batchSize=batchSize,
                                     queryCount=True,
                                     valueOption=valueOption)
    mqueryOption0 = queryOption_type(batchNo=batchNo,
                                     batchSize=batchSize,
                                     queryCount=True,
                                     valueOption=valueOption)
    # ans = client.service.query(sessionId.sessionId, "cxSqlKHCJTJ_GPXZ", params, "", mqueryOption)
    # print(ans)

    tasks = [
        # client.service.login("ZXQH_GPXZ", "GPXZ123321", "myapp", "plain", ""),
        client.service.login("ZXQH_GPXZ", "GPXZ123321", "myapp", "plain", ""),
        # client.service.query(sessionId, "cxSqlKHCJTJ_GPXZ", params, "", mqueryOption),
        # client.service.query(sessionId, "cxSqlKHCJTJ_GPXZ", params, "", mqueryOption2),  # takes 1 sec
    ]
    future = asyncio.gather(*tasks, return_exceptions=True)
    sessionId = []

    def set_sessionId(future):
        ans = future.result()

        sessionId.append(ans[0].sessionId)
        tasks = [
            client.service.query(sessionId, "cxSqlKHCJTJ_GPXZ", params, "",
                                 mqueryOption),
            client.service.query(sessionId, "cxSqlKHCJTJ_GPXZ", params, "",
                                 mqueryOption2),  # takes 1 sec
        ]
        future2 = asyncio.gather(*tasks, return_exceptions=True)
        future2.add_done_callback(handle_future)
        loop.run_until_complete(future2)
        return

    future.add_done_callback(set_sessionId)

    st = time.time()
    loop.run_until_complete(future)
    loop.run_until_complete(transport.session.close())
    print("time: %.2f" % (time.time() - st))
    print("result: %s" % result)
    print("")
    print("sessionId:{sessionId}".format(sessionId=sessionId))
    return result
Exemple #13
0
def run_async():
    print("async example")
    print("=============")

    result = []

    def handle_future(future):
        result.extend(future.result())
        print(future.result())
        # [unicode(x.strip()) if x is not None else '' for x in row]
        record_list = []
        for row in result:
            if len(row.records) == 0:
                continue
            record_list.extend(row.records)
        record_list = [item.values for item in record_list]
        # record_list = [[record for record in row.records] for row in result]
        df = pd.DataFrame.from_records(record_list, columns=None,)
        df.to_csv('../output/crm_test.csv', encoding='gbk')
        asyncio.ensure_future(logout())




    loop = asyncio.get_event_loop()
    wsdl = 'http://10.21.2.75:8080/service/LBEBusiness?wsdl'
    cache = SqliteCache(path='./sqlite.db', timeout=3600)
    transport = AsyncTransport(loop, cache=cache)
    client = zeep.Client(wsdl, transport=transport)
    # login_ans = client.service.login("ZXQH_GPXZ", "GPXZ123321", "myapp", "plain", ""),
    # sessionId = login_ans[0].sessionId
    async def login(future):
        result = await client.service.login("ZXQH_GPXZ", "GPXZ123321", "myapp", "plain", ""),
        global sessionId
        sessionId = result[0].sessionId
        future.set_result(result[0].sessionId)
    async def logout():
        global sessionId
        result = await client.service.logout(sessionId)

        result = await transport.session.close()
        loop.stop()



    def send_quests(future):
        sessionId = future.result()
        df = pd.read_excel('./客户名单(服务器托管).xlsx')
        df = df.apply(pd.to_numeric, errors='ignore')
        user_ids = df['资金账号'].tolist()
        user_ids = user_ids[0:20]
        tasks = [
            setup_req(sessionId, str(user_id)) for user_id in user_ids
        ]

        future2 = asyncio.gather(*tasks, return_exceptions=True)
        future2.add_done_callback(handle_future)


    async def setup_req(sessionId, user_id,):
        lbParameter_type = client.get_type('ns0:lbParameter')
        queryOption_type = client.get_type('ns0:queryOption')

        par_dict = {"KSRQ": "2018-11-01", "JSRQ": "2018-11-10", "KHH": user_id}
        params = []
        for key in par_dict:
            val = par_dict[key]
            temp_lbParameter = lbParameter_type(name=key, value=val)
            params.append(temp_lbParameter)

        valueOption_type = client.get_type('ns0:valueOption')
        valueOption = valueOption_type('VALUE')
        batchNo = 1
        batchSize = 3000
        mqueryOption = queryOption_type(batchNo=batchNo, batchSize=batchSize,
                                        queryCount=True, valueOption=valueOption)
        #  waits 1 second
        # delay_seconds = random.randrange(5)
        # await asyncio.sleep(delay_seconds)
        # await asyncio.sleep(1)
        result = await client.service.query(sessionId, "cxSqlKHCJMX", params, "", mqueryOption)

        return result

    lbParameter_type = client.get_type('ns0:lbParameter')
    queryOption_type = client.get_type('ns0:queryOption')

    par_dict = {"KSRQ": "2018-11-01", "JSRQ": "2018-11-10", "KHH": "0000050067"}
    params = []
    for key in par_dict:
        val = par_dict[key]
        temp_lbParameter = lbParameter_type(name=key, value=val)
        params.append(temp_lbParameter)

    valueOption_type = client.get_type('ns0:valueOption')
    valueOption = valueOption_type('VALUE')
    batchNo = 1
    batchSize = 3000
    mqueryOption = queryOption_type(batchNo=batchNo, batchSize=batchSize, queryCount=True, valueOption=valueOption)



    # st = time.time()
    # loop.run_until_complete(future)
    # loop.run_until_complete(transport.session.close())
    # print("time: %.2f" % (time.time() - st))
    # print("result: %s" % result)
    # print("")
    # print("sessionId:{sessionId}".format(sessionId=sessionId))
    loop = asyncio.get_event_loop()
    future = asyncio.Future()
    asyncio.ensure_future(login(future))
    future.add_done_callback(send_quests)
    try:
        loop.run_forever()
    finally:
        loop.close()
    return result
Exemple #14
0
        params.append(temp_lbParameter)
    valueOption_type = client.get_type('ns0:valueOption')
    valueOption = valueOption_type('VALUE')
    batchNo = 1
    batchSize = 3000
    mqueryOption = queryOption_type(batchNo=batchNo, batchSize=batchSize, queryCount=True, valueOption=valueOption)
    await client.service.query(sessionId.sessionId, "cxSqlKHCJMX", params, "", mqueryOption)


df = pd.read_excel('../input/客户名单(服务器托管).xlsx')
df = df.apply(pd.to_numeric, errors='ignore')
df['资金账号']
ans_list = []
loop = asyncio.get_event_loop()

transport = AsyncTransport(loop, cache=None)

# for i in df['资金账号']:
#     t = str(i)
#     print(t)
#     ans = get_data_by_userid(t)
#     ans_list.append(ans)
userids = df['资金账号'].tolist()
# tasks = list(map(get_data_by_userid, userids))
string_type = client.get_type('xsd:string')
lbParameter_type = client.get_type('ns0:lbParameter')
queryOption_type = client.get_type('ns0:queryOption')
par_dict = {"KSRQ": "2018-11-01", "JSRQ": "2018-11-10", "KHH": '100100207'}
params = []
for key in par_dict:
    val = par_dict[key]
Exemple #15
0
 def _get_transport(self):
     return AsyncTransport(loop=self.__loop, operation_timeout=self.timeout)