Exemplo n.º 1
0
def process(url, name):
    """Main process to translate the given URL."""
    survey_dict = query.get_survey_dict(url)
    map_path = os.path.join(survey_dict['survey_path'], 'limesurvey_map.csv')
    survey_map = database.read_csv_file(map_path)
    untranslated_path = os.path.join(survey_dict['survey_path'], name)
    untranslated_rows = database.read_csv_file(untranslated_path)
    untranslated_list = list(untranslated_rows)
    untranslated_header = untranslated_list[0]
    # Determine index when the submission data starts:
    data_index = get_data_index(untranslated_header)
    translated_map = get_translated_map(survey_map, untranslated_header)
    # Prepare the translated output
    translated_header = get_translated_header(
        untranslated_header, translated_map, data_index)
    translation_list = [translated_header]
    for row in filter(None, untranslated_list[1:]):
        translated_row = translate_row(row, translated_map, data_index)
        assert len(translated_header) == len(translated_row), 'Missmatch row count'
        translation_list.append(translated_row)
    logger.info('Translated: %s', len(translation_list) - 1)
    translated_path = os.path.join(survey_dict['survey_path'], 'translated.csv')
    database.save_csv_file(translated_path, translation_list)
    return True
Exemplo n.º 2
0
def save_sent_submissions(sent_submissions, survey_dict):
    logger.info('Saving sent submissions: `%s`', len(sent_submissions))
    file_path = os.path.join(survey_dict['survey_path'], 'submissions.csv')
    database.save_csv_file(file_path, sent_submissions.values())
    return sent_submissions