Skip to content

Fail to Download all status version #10

@fmigone

Description

@fmigone

Bug Report

Hey,
We use survey solutions in our survey in Côte d'Ivoire. We automate downloading data for all members of TEAM who need to get access to data to avoid to give HQ access to too many persons. Doing so, we write the following code.

#!/usr/bin/env python

coding: utf-8

In[1]:

import ssaw
import pandas as pd
import os
from ssaw import Client
from ssaw import ExportApi
from ssaw.exceptions import NotFoundError
from ssaw.models import ExportJob
from zipfile import ZipFile
from datetime import datetime

username = os.getenv('USERNAME')
client = ssaw.Client('http://YYYYYYYYYYYYYYY', api_user='ZZZZZZZZ',api_password='KKKKKKKKKKKK',workspace='PPPPPP')
variable_qx = 'Qx_eec_final_pas2VF'
one_drive = "XXXXXXXXXXXXXXXXXXXXXXXXXXXX"
download_path = "ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"
download_type = 'STATA'
download_status = 'All'

current_datetime = datetime.now().strftime("%Y-%m-%d %H")
str_current_datetime = str(current_datetime)
folder_name = "\T "+str_current_datetime

isExist = os.path.exists(one_drive + download_path + folder_name)
if not isExist:
os.mkdir(one_drive + download_path + folder_name)

Lisquestionnaire= pd.DataFrame(columns=['id','questionnaire_id','version','title','variable'])

for ques in ssaw.QuestionnairesApi(client).get_list():
entree=[ques.id,ques.questionnaire_id,ques.version,ques.title,ques.variable]
if ques.variable == variable_qx and ques.version>=20 :
Lisquestionnaire.loc[len(Lisquestionnaire)] = entree

def download_data(questionnaire_id,version):

#Vérification de l'existence du dossier et création s'il n'existe pas
isExist = os.path.exists(one_drive + download_path + folder_name + "\\Data_ex\\" + questionnaire_id + "V" + str(version) )
if not isExist:
    os.makedirs(one_drive + download_path + folder_name + "\\Data_ex\\" + questionnaire_id + "V" + str(version) )

#Téléchargement du fichier de données
filename = ExportApi(client).get(export_type="STATA",interview_status='All',export_path=one_drive + download_path + folder_name + "\\Data_ex\\" + questionnaire_id + "V" + str(version),generate=True,show_progress=True,
                                 questionnaire_identity=questionnaire_id + "$" + str(version))
#extraction des fichiers zip si le fichier de données "filename" n'est pas vide
if filename is not None:
    with ZipFile(filename, 'r') as zObject:
        zObject.extractall(path=one_drive + download_path + folder_name + "\\Data_ex\\" + questionnaire_id + "V" + str(version))


#Vérification de l'existence du dossier et création s'il n'existe pas
isExist = os.path.exists(one_drive + "Donnees_Journalieres_Sup" + folder_name + "\\Data_ex\\" + questionnaire_id + "V" + str(version))
if not isExist:
    os.makedirs(one_drive + "Donnees_Journalieres_Sup" + folder_name + "\\Data_ex\\" + questionnaire_id + "V" + str(version))

#extraction des fichiers zip dans un dossier accessible à tous
if filename is not None:
    with ZipFile(filename, 'r') as zObject:
        zObject.extractall(path=one_drive + "Donnees_Journalieres_Sup" + folder_name + "\\Data_ex\\" + questionnaire_id + "V" + str(version))

#Téléchargement des données
for i in range(len(Lisquestionnaire)):
try:
download_data(Lisquestionnaire.loc[i, "questionnaire_id"], Lisquestionnaire.loc[i, "version"])
except (RuntimeError, TypeError, NameError,ValueError) :
pass

Summary

But so many times, we get only one status data even if we indicate willing all status with ,interview_status='All'. Sometimes, it gets us only completed interviews or only ApprovedBySup interviews.

Current behavior

How to reproduce

Expected behavior

Can you help us about that ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions