def fetch_worldcity(country, city, code, loc): cursor = local_conn.cursor() if ("'") in city: city = city.replace("'","''") custom_tab = "cust_" + country.lower() sql = "select name from custom.sqlite_master where type='table'" att_tables = [] for row in local_conn.execute(sql): att_tables.append(str(row[0])) sql = "select CC, AC, Ciudad, Latitud, Longitud from '%s' where Ciudad == '%s' and AC == '%s' " % (country, city, code) if custom_tab in att_tables: union = " union select CC, AC, Ciudad, Latitud, Longitud from '%s' where Ciudad == '%s' and AC == '%s' " % (custom_tab, city, code) else: union = "" sql += union cursor.execute(sql) loc.country_code, loc.region_code, loc.city, loc.latitud, loc.longitud = cursor.next() loc.latdec = degtodec(loc.latitud.strip()) loc.longdec = degtodec(loc.longitud.strip()) fetch_region(cursor, loc) fetch_country(cursor, loc) fetch_zone(cursor, loc)
def fetch_blindly(country, city, loc): '''get city data''' cursor = local_conn.cursor() if ("'") in city: city = city.replace("'","''") sql = "select CC, AC, Ciudad, Latitud, Longitud from '%s' where Ciudad=='%s'" % (country, city) cursor.execute(sql) try: loc.country_code, loc.region_code, loc.city, loc.latitud, loc.longitud = cursor.next() except StopIteration: return "localidad no encontrada: %s" % city loc.latdec = degtodec(loc.latitud) loc.longdec = degtodec(loc.longitud) fetch_region(cursor, loc) fetch_country(cursor, loc) fetch_zone(cursor, loc) return loc