# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

from odt_parse import OdtData
from odt_diff import odt_compare

import csv, glob, zipfile

HOME_FOLDER = '../'
SUBMISSION_FOLDER = HOME_FOLDER + 'PS1002-2-20172018-Document libro predefinidos.odt, grups de dijous-3219356'
user_folder = glob.glob(SUBMISSION_FOLDER + '/*')

ref_name = 'libro_predefinidos.odt'
ref = OdtData(ref_name)

with open(SUBMISSION_FOLDER + '.txt', 'w') as f:
    counter = 0
    for ufo in user_folder:
        user_files = glob.glob(ufo + '/*')
        for ufi in user_files:
            tokens = ufi.split('/')
            filename = tokens[-1]
            user_data = tokens[-2]
            user_name, user_id, _, submission_type, _ = user_data.split('_')
            fns = filename.split('.')
            if len(fns) > 1:
                extension = fns[-1]
            else:
                extension = ''
            row = [user_name, user_id, submission_type, filename, extension]
            f.write(user_name + '\n' + '-'*len(user_name) + '\n')
            if filename != ref_name:
                f.write('\nNombre de fichero: %s\n' % filename)
            if extension == 'odt':
                doc = OdtData( ufi )
                if doc.err:
                    f.write('Error de lectura de fichero\n')                   
                else:
                    f.write(odt_compare(ref, doc))
            else:
                f.write('Extensión de fichero incorrecta\n')
            f.write('\n' + '#'*40 + '\n\n')
            counter += 1
    print('%d ficheros procesados.' % counter)



StarcoderdataJupyterScriptsDedupFiltered