1

I am requesting data via Mailchimp Marketing API using Batch Operations. I receive a response_body_url which once clicked, downloads gzipped files locally.

A GET request to the response_body_url returns a gzipped tar archive of JSON files.

But I would want to extract the same on Python and load it as a JSON array. Mailchimp has shared a guide about the same, but they have used a function process_batch_archive and have not defined what this function is or how it works. enter image description here

Here is the link to the guide: Link Can anyone help me achieve the expected result? Thank you.

1 Answers1

0
import tarfile
def process_batch_archive():
    if fname.endswith("tar.gz"):
        tar = tarfile.open(fname, "r:gz")
        tar.extractall()
        tar.close()
    elif fname.endswith("tar"):
        tar = tarfile.open(fname, "r:")
        tar.extractall()
        tar.close()