From f18321dbc8cd55d8fc6568d787a07c22d201d003 Mon Sep 17 00:00:00 2001 From: yaderv Date: Thu, 24 Feb 2011 15:35:17 +0000 Subject: code improved --- (limited to 'archivo.py') diff --git a/archivo.py b/archivo.py index 1932e0f..0ffda53 100644 --- a/archivo.py +++ b/archivo.py @@ -138,39 +138,39 @@ def borrar_dato(indice, indice_lista, path): else: return 1 -def dict_meses(path, fecha=None): +def dict_meses(path, fecha, opcion=0): '''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:]) + + indice = fecha[:4] + fecha = int(fecha[4:]) - if not os.path.exists(path): - _log.debug('THE FILE LISTA_DIAS DID NOT EXISTS') - f = open(path, 'wb') - datos = {} - - else: + if os.path.exists(path): f = open(path, 'rb+wb') datos = pickle.load(f) - if fecha is not None: - if indice in datos: - if not fecha in datos[indice]: - datos[indice].append(fecha) - else: - pass - else: - datos[indice] = [] - - + if not indice in datos: + datos[indice] = [] + + if opcion: + if not fecha in datos[indice]: + datos[indice].append(fecha) + else: + _log.debug('THE FILE LISTA_DIAS DID NOT EXISTS') + f = open(path, 'wb') + datos = {} + datos[indice] = [] + f.seek(0) pickle.dump(datos, f) f.close() return datos def borrar_dict_meses(path, fecha): + '''delete from the dict the date when the + activity stack is empty''' + path = path + '/data/lista_dias.pkl' indice = fecha[:4] fecha = int(fecha[4:]) -- cgit v0.9.1