def get_words(word=None, abcs=None, only_nouns=True, skip_offensive=True, min_length=MIN_LENGTH, max_results=MAX_RESULTS, lang=LANG): if not word: return None, 0 lc = [] # count letters in the `word` for l in ABC: lc.append("%i, " % (word.count(l))) # compile DB query query = """CALL GET_WORDS(%s %i, %i, %i, %i, %i)""" % ( "".join(lc), min_length, max_results, lang, 1 if only_nouns else 0, 1 if skip_offensive else 0) cnx = db.connect(DB_USER, DB_PASS, DB_NAME, host=DB_HOST, unix_socket=DB_UNIX) rc, results = db.execute(cnx, query) db.close(cnx) if rc and results and len(results) > 0: return results[0] return None, 0
def home(): db = connection.connect() query = 'select curdate()' cursor = connection.executeQuery(db, query) date = cursor.fetchone() connection.disconnect(db) return "Hello! current date is {}.".format(date[0])
def path_table(): nombre_archivo = request.form['file'] print('buscando archivo: {} ...'.format(nombre_archivo)) if len(nombre_archivo) < 5: return "El nombre del archivo no es valido." db = connection.connect() cursor = connection.executeQuery( db, 'SELECT tabla_path AS url FROM {} WHERE tabla_path like "%{}" LIMIT 1'. format(tabla, nombre_archivo)) print('Ejecutando querie: {}'.format( 'SELECT tabla_path AS url FROM {} WHERE tabla_path like "%{}" LIMIT 1'. format(tabla, nombre_archivo))) data = cursor.fetchone() if data is None: return 'Archivo de tabla no existe' else: print(data[0]) return data[0]
def actualizar_tablas(): db = connection.connect() truncate = connection.executeUpdate(db, 'TRUNCATE TABLE {}'.format(tabla)) if truncate: print('Actualizando arbol de tablas en la bd') for dirpath, dirnames, filenames in os.walk(ruta_raiz): print('debugueando') if filenames: for file_name in filenames: if file_name.find('.parametros') > 0 and file_name.find( '.parametros') + len('.parametros') == len( file_name): dirpath_encode = dirpath.encode( 'utf-8', 'surrogateescape').decode('utf-8', 'replace') filepath_encode = file_name.encode( 'utf-8', 'surrogateescape').decode('utf-8', 'replace') query = 'INSERT INTO tablas_parametros (tabla_path) VALUES ("{}")'.format( dirpath_encode + '/' + filepath_encode) connection.executeUpdate(db, query) connection.disconnect(db) return "Proceso de actualizacion de tablas realizado exitosamente."
return "{0} {1} {2} {3} {4} {5}".format(src.name, src.pos.ra.deg, src.pos.dec.deg, src.flux, src.alpha, src.beta) def insert_src(src, cur): print(src) cur.execute(""" INSERT INTO sources (source, RAJ2000, DecJ2000, flux, alpha, beta) VALUES (%s, %s, %s, %s, %s, %s); """, (src.name, src.pos.ra.deg, src.pos.dec.deg, src.flux, src.alpha, src.beta)) return if __name__ == "__main__": conn = mdb.connect() cur = conn.cursor() casa = Source("CasA", SkyCoord("23h23m24.000s +58d48m54.00s"), 13000., -0.5, 0.0 ) cyga = Source("CygA", SkyCoord("19h59m28.35663s +40d44m02.0970s"), 9000., -1.0, 0.0 ) crab = Source("Crab", SkyCoord("05h34m31.94s +22d00m52.2s"), 1500., -0.5, 0.0 ) vira = Source("VirA", SkyCoord("12h30m49.42338s +12d23m28.0439s"), 1200., -1.0, 0.0 ) pica = Source("PicA", SkyCoord("05h19m49.7229s -45d46m43.853s"), 570., -1.0, 0.0 ) hera = Source("HerA", SkyCoord("16h51m11.4s +04d59m20s"), 520., -1.1, 0.0 ) hyda = Source("HydA", SkyCoord("09h18m05.651s -12d05m43.99s"), 350., -0.9, 0.0 ) sources = [casa, cyga, crab, vira, pica, hera, hyda] for src in sources: insert_src(src, cur) conn.commit()