raise Exception('\nNo databases selected! Goodbye.\n') except Exception as e: print e sys.exit() coastal_counties_db = Database(coastal_counties_db_file) for i, tweet_db_file in enumerate(tweet_db_files): print '{} out of {} databases'.format(i + 1, len(tweet_db_files)) current_coastal_counties_db_file = os.path.join( RESULTS_PATH, os.path.split(tweet_db_file)[1]) current_coastal_counties_db = Database( current_coastal_counties_db_file) other_db_name = current_coastal_counties_db.attach( coastal_counties_db_file) current_coastal_counties_db.cursor.execute('BEGIN') current_coastal_counties_db.cursor.execute(""" DELETE FROM {ttb} WHERE fips NOT IN (SELECT fips FROM {odb}.counties_ngl) """.format(ttb='tweets', odb=other_db_name)) current_coastal_counties_db.connection.commit() # coastal_counties_db.cursor.execute("""DETACH DATABASE '{}'""".format(other_db_name)) current_coastal_counties_db.connection.close() coastal_counties_db.connection.close()