From 94ea0d4c70473a4dc0a0d09664083dab8aafc28f Mon Sep 17 00:00:00 2001 From: Yader Velásquez Date: Tue, 28 Dec 2010 19:11:21 +0000 Subject: nueva funcion de importar --- (limited to 'archivo.py') diff --git a/archivo.py b/archivo.py index be4b5a4..03af5c0 100644 --- a/archivo.py +++ b/archivo.py @@ -66,22 +66,48 @@ def crear_modelo(indice, path): archivo.close() return modelo -def abrir_efemeride(path): - '''open the ephemeris file and return a data dictionary''' +def comprobar_efemeride(path): + '''test is the ephemeri file exists''' path = path + '/data/efemerides.pkl' if not os.path.exists(path): - _log.debug('THE FILE EFEMERIDES DID NOT EXISTS') - archivo = open(path, 'wb') - texto = {} - pickle.dump(texto, archivo) - archivo.close() + return False else: - _log.debug('THE FILE EPHEMERIS EXISTS') - archivo = open(path, 'rb') - texto = pickle.load(archivo) - archivo.close() + return True + +def abrir_efemeride(path): + '''open the ephemeris file and return a data dictionary''' + path = path + '/data/efemerides.pkl' + #if not os.path.exists(path): + # _log.debug('THE FILE EFEMERIDES DID NOT EXISTS') + # archivo = open(path, 'wb') + # texto = {} + # pickle.dump(texto, archivo) + # archivo.close() + #else: + _log.debug('THE FILE EPHEMERIS EXISTS') + archivo = open(path, 'rb') + texto = pickle.load(archivo) + archivo.close() return texto +def guardar_efemeride(path, file_name): + '''import, convert and save a new ephemeris database''' + path = path + '/data/efemerides/pkl' + di = {} + file = open(file_name, 'r') + lines = file.readlines() + for i in range(len(lines)): + current_text = lines[i][10 : len(lines[i]) - 2] + + for j in range(30, len(current_text),30): + current_text = current_text[:j] + '\n' + current_text[j + 1 :] + current_id = lines[i][0 : 8] + di[current_id] = current_text + file_new = open(path, 'wb') + pickle.dump(di,file_new) + file_new.close() + file.close() + def guardar_dato(indice, contenido, categoria, bolean, path): '''save the content in a file, add the content to a dictionary->list''' path = path + '/data/actividades.pkl' -- cgit v0.9.1