Download 17/replication_package/code/lib/data_helpers/qualtricsapi2.py from chuxuan/REPRO-Bench: direct link, hf CLI and curl.
- Browser
- Download file 2.07 kB
-
https://huggingface.co/datasets/chuxuan/REPRO-Bench/resolve/main/17/replication_package/code/lib/data_helpers/qualtricsapi2.py
- Command line
-
hf download hf://datasets/chuxuan/REPRO-Bench/17/replication_package/code/lib/data_helpers/qualtricsapi2.py
-
curl -L -o qualtricsapi2.py https://huggingface.co/datasets/chuxuan/REPRO-Bench/resolve/main/17/replication_package/code/lib/data_helpers/qualtricsapi2.py
2.07 kB
| import requests | |
| import zipfile | |
| import json | |
| import io, os | |
| import sys | |
| import re | |
| def export_survey(apiToken, surveyId, dataCenter, fileFormat,downloadDir, exportResponsesInProgress): | |
| surveyId = surveyId | |
| fileFormat = fileFormat | |
| dataCenter = dataCenter | |
| # Setting static parameters | |
| requestCheckProgress = 0.0 | |
| progressStatus = "inProgress" | |
| baseUrl = "https://{0}.qualtrics.com/API/v3/surveys/{1}/export-responses/".format(dataCenter, surveyId) | |
| headers = { | |
| "content-type": "application/json", | |
| "x-api-token": apiToken, | |
| } | |
| # Step 1: Creating Data Export | |
| downloadRequestUrl = baseUrl | |
| downloadRequestPayload = '{"format":"' + fileFormat + '",' '"useLabels": true, "exportResponsesInProgress":' + exportResponsesInProgress +'}' | |
| downloadRequestResponse = requests.request("POST", downloadRequestUrl, data=downloadRequestPayload, headers=headers) | |
| progressId = downloadRequestResponse.json()["result"]["progressId"] | |
| print(downloadRequestResponse.text) | |
| # Step 2: Checking on Data Export Progress and waiting until export is ready | |
| while progressStatus != "complete" and progressStatus != "failed": | |
| print("progressStatus=", progressStatus) | |
| requestCheckUrl = baseUrl + progressId | |
| requestCheckResponse = requests.request("GET", requestCheckUrl, headers=headers) | |
| requestCheckProgress = requestCheckResponse.json()["result"]["percentComplete"] | |
| print("Download is " + str(requestCheckProgress) + " complete") | |
| progressStatus = requestCheckResponse.json()["result"]["status"] | |
| # step 2.1: Check for error | |
| if progressStatus is "failed": | |
| raise Exception("export failed") | |
| fileId = requestCheckResponse.json()["result"]["fileId"] | |
| # Step 3: Downloading file | |
| requestDownloadUrl = baseUrl + fileId + '/file' | |
| requestDownload = requests.request("GET", requestDownloadUrl, headers=headers, stream=True) | |
| # Step 4: Unzipping the file | |
| zipfile.ZipFile(io.BytesIO(requestDownload.content)).extractall(downloadDir) | |
| print('Complete') |