diff options
Diffstat (limited to 'archivo.py')
-rw-r--r-- | archivo.py | 24 |
1 files changed, 17 insertions, 7 deletions
@@ -135,23 +135,33 @@ def borrar_dato(indice, indice_lista, path): f.flush() f.close() -def lista_meses(path): +def dict_meses(path, fecha=None): + '''Create if not exists and return a data + dictionary with the months index''' path = path + '/data/lista_dias.pkl' + if fecha is not None: + indice = fecha[:4] + fecha = int(fecha[4:]) - meses = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'ago', 'sep', - 'oct', 'nov', 'dec'] - if not os.path.exists(path): _log.debug('THE FILE LISTA_DIAS DID NOT EXISTS') f = open(path, 'wb') datos = {} - for i in meses: - datos[i] = [] pickle.dump(datos, f) else: - f = open(path, 'rb + wb') + f = open(path, 'rb+wb') datos = pickle.load(f) + + if fecha is not None: + if indice in datos: + datos[indice] = lista_fechas.append(fecha) + else: + lista_fechas = [] + lista_fechas.append(fecha) + datos[indice] = lista_fechas + pickle.dump(datos, f) + f.seek(0) f.flush() f.close() |