from src import connection INSERT_BACKUP_SQL = """ INSERT INTO youtube_channel_video_status_deleted ( id, youtube_video_id, youtube_channel_id, video_search_time, release_id, track_id, track_insert_time, youtube_asset_id, asset_insert_time, ownership_insert_time, youtube_claim_id, claim_insert_time, asset_match_insert_time, youtube_reference_id, reference_insert_time, in_processing, last_updated, error_type, inserted_datetime) SELECT id, youtube_video_id, youtube_channel_id, video_search_time, release_id, track_id, track_insert_time, youtube_asset_id, asset_insert_time, ownership_insert_time, youtube_claim_id, claim_insert_time, asset_match_insert_time, youtube_reference_id, reference_insert_time, in_processing, last_updated, error_type, NOW() FROM youtube_channel_video_status WHERE youtube_video_id IN (%s) """ DELETE_SQL = """ DELETE FROM youtube_channel_video_status WHERE youtube_video_id IN (%s) """ def clear_bacon_history(youtube_id_list): print("Running script to clear bacon history") placeholders = ",".join(["%s"] * len(youtube_id_list)) bindings = tuple(youtube_id_list) db_connection = connection.ar_db_connection() cursor = db_connection.cursor() try: cursor.execute(INSERT_BACKUP_SQL % placeholders, bindings) print("Records inserted: %s" % cursor.rowcount) cursor.execute(DELETE_SQL % placeholders, bindings) print("Records deleted: %s" % cursor.rowcount) db_connection.commit() finally: cursor.close() db_connection.close()