def call_apis_async(location):
    start = time.time()
    loop = asyncio.get_event_loop()

    f1 = asyncio.Future()
    f2 = asyncio.Future()

    f1.add_done_callback(callback_weather)
    f2.add_done_callback(callback_weather_forecast)

    tasks = [Forecast.get_weather(f1, location), Forecast.get_weather_forecast(f2, location)]

    loop.run_until_complete(asyncio.wait(tasks))

    loop.close()

    LOGGER.info(f'Total Time Taken {time.time() - start}')
    print()
Beispiel #2
0
def call_fund_api():
    LOGGER.info("call_fund_api")

    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)

    f1 = asyncio.Future()

    f1.add_done_callback(callback_fund)

    tasks = [Forecast.get_fund_price(f1)]
    loop.run_until_complete(asyncio.wait(tasks))

    loop.close()
    print()
Beispiel #3
0
def call_weather_api(location):
    LOGGER.info("call_weather_api")

    try:
        loop = asyncio.new_event_loop()
        asyncio.set_event_loop(loop)

        f1 = asyncio.Future()

        f1.add_done_callback(callback_weather)

        tasks = [Forecast.get_weather(f1, location)]
        loop.run_until_complete(asyncio.wait(tasks))

        loop.close()
        print()
    except Exception as ex:
        LOGGER.error(f'call_weather_api : {repr(ex)}')