async def sample_list_all_translations_async():
    import os
    # [START list_all_translations_async]
    from azure.core.credentials import AzureKeyCredential
    from azure.ai.translation.document.aio import DocumentTranslationClient

    endpoint = os.environ["AZURE_DOCUMENT_TRANSLATION_ENDPOINT"]
    key = os.environ["AZURE_DOCUMENT_TRANSLATION_KEY"]

    client = DocumentTranslationClient(endpoint, AzureKeyCredential(key))
    async with client:
        operations = client.list_all_translation_statuses(
        )  # type: AsyncItemPaged[TranslationStatus]

        async for operation in operations:
            print("ID: {}".format(operation.id))
            print("Status: {}".format(operation.status))
            print("Created on: {}".format(operation.created_on))
            print("Last updated on: {}".format(operation.last_updated_on))
            print("Total number of operations on documents: {}".format(
                operation.documents_total_count))
            print("Total number of characters charged: {}".format(
                operation.total_characters_charged))

            print("\nOf total documents...")
            print("{} failed".format(operation.documents_failed_count))
            print("{} succeeded".format(operation.documents_succeeded_count))
            print("{} cancelled\n".format(operation.documents_cancelled_count))
示例#2
0
async def sample_list_translations_with_filters_async():
    # import libraries
    from azure.core.credentials import AzureKeyCredential
    from azure.ai.translation.document.aio import DocumentTranslationClient

    from datetime import datetime

    # obtain client secrets
    endpoint = os.environ["AZURE_DOCUMENT_TRANSLATION_ENDPOINT"]
    key = os.environ["AZURE_DOCUMENT_TRANSLATION_KEY"]

    # authorize client
    client = DocumentTranslationClient(endpoint, AzureKeyCredential(key))
    async with client:
        # set your filters
        '''
            Note:
                these are just sample values for the filters!
                please comment/uncomment/change what you are interested in using.
        '''
        start = datetime(2021, 4, 12)
        end = datetime(2021, 4, 14)
        statuses = ["Cancelled", "Failed"]
        order_by = ["createdDateTimeUtc desc"]
        results_per_page = 2
        skip = 3

        # list translation operations
        submitted_translations = client.list_all_translation_statuses(
            # filters
            statuses=statuses,
            created_after=start,
            created_before=end,
            # ordering
            order_by=order_by,
            # paging
            skip=skip,
            results_per_page=results_per_page).by_page()

        # check statuses
        async for page in submitted_translations:
            async for translation in page:
                display_translation_info(translation)