[Python] Optimizing a workflow for contact enrichment

Discussão em 'Python' iniciado por Stack, Março 7, 2025.

  1. Stack

    Stack Membro Participativo

    I know this is a noob question but I could do with some guidance please.

    I have a list of people for whom I want to get their contact data (B2B sales prospecting use case). I'm using the surfe api which breaks the request into two parts. 1 to tell them which person I want the contact details for and another to get the data back.

    here https://developers.surfe.com/public-001-create-enrichment and [https://developers.surfe.com/public-002-get-enrichment] (https://developers.surfe.com/public-002-get-enrichment)

    For that second request there's a 'Status' field, which initially says 'IN_PROGRESS' I assume while they're finding the information and then it goes to 'COMPLETE' when my data is ready.

    To manage this I've put a while loop which keeps looping until the status is no longer 'IN_PROGRESS' with a 0.5 second wait between.

    This seems inefficient. Is there a way I can make this better?

    url = "https://api.surfe.com/v1/people/enrichments/" + response.json()['id']
    response = requests.request("GET", url, headers=headers)
    while response.json()['status'] == "IN_PROGRESS":
    response = requests.request("GET", url, headers=headers)
    time.sleep(0.5)
    print('waiting')
    print('complete')
    print(response.text)


    enter image description here

    Continue reading...

Compartilhe esta Página