import argparse import config import connection def get_argument(): parser = argparse.ArgumentParser(prefix_chars='+') parser.add_argument( 'project_id', nargs='+', help='Please enter the project_id' ) args = parser.parse_args() return args.project_id def undelete_projects(project_id_list, logger): if len(project_id_list) <= 1000: ids_string = ','.join(f'"{i}"' for i in project_id_list) logger.info('Argument is %s' % ids_string) sql_update = f"""UPDATE project SET deletions = 'N' WHERE project_id IN ({ids_string})""" db_connection = connection.database_connection() cursor = db_connection.cursor() cursor.execute(sql_update) db_connection.commit() logger.info('Records updated: %s' % cursor.rowcount) db_connection.close() else: logger.info('Number of project IDs should not be more than 1000') def main(correlation_id=None): logger = config.get_current_logger(correlation_id) logger.info('Running script to undelete projects') project_id_list = get_argument() undelete_projects(project_id_list, logger) if __name__ == '__main__': main()