示例#1
0
async def sync():
    fit_client = Fitbit(user=session["user"], access_token=app.secret_key)
    result = fit_client.init_sync()
    # Create a producer client to send messages to the event hub.
    # Specify a connection string to your event hubs namespace and
    # the event hub name.
    producer = EventHubProducerClient.from_connection_string(
        conn_str=app.config["EVENT_HUB_CONN_STR"])
    async with producer:
        # Create a batch.
        event_data_batch = await producer.create_batch()

        for item in result:
            print(item)
            event_data_batch.add(EventData(json.dumps(item, indent=4)))

        # Send the batch of events to the event hub.
        await producer.send_batch(event_data_batch)