Since survey solutions doesn’t have data export in excel, I am creating a data export feature in my own website using python API.
what I have done is, generate and read file in spss and convert in into dataframe:
import zipfile
import pandas as pd
import pyreadstat
import tempfile
import ssaw
from ssaw.models import ExportJob
from ssaw import ExportApi
client = ssaw.Client('survey solutions link',
token='token code')
job = ExportJob(questionnaire_id="questionnaire_id", export_type="SPSS", interview_status='Completed')
r = ExportApi(client).start(job, wait=True,show_progress=True)
filename = ExportApi(client).get(export_type="SPSS",questionnaire_identity="questionnaire_id", interview_status='Completed')
zip_file_path = filename
# Name of the .sav file within the zip file
sav_file_name = 'questionnaire_variable.sav'
with zipfile.ZipFile(zip_file_path, 'r') as zip_file:
# Extract the .sav file to a temporary directory
with tempfile.TemporaryDirectory() as temp_dir:
zip_file.extract(sav_file_name, temp_dir)
# Specify the extracted .sav file path
extracted_file_path = f"{temp_dir}/{sav_file_name}"
# Load the .sav file using pyreadstat
df, metadata = pyreadstat.read_sav(extracted_file_path, apply_value_formats=True)
display(df)
above code generates spss format dataset in survey solutions and the data into dataframe.
I need help with listing the questionnaire that I have imported in the survey solutions so that I can list those questionnaire in my website and export the data of that selected questionnaire.