@@ -0,0 +1,1396 @@
+# The purpose of this script to update database with a CSV%0A%0Aimport os%0Aimport sys%0A%0Aimport psycopg2%0Aimport dotenv%0A%0A# Load environment variable from a .env file%0Adotenv.load_dotenv('.env')%0A%0Acsv_path = sys.argv%5B1%5D%0Apostgres_url = os.getenv('DATABASE_URL')%5B11:%5D%0Auser_tokens = postgres_url.split(':')%0Auser_name = user_tokens%5B0%5D%0Apassword_tokens = user_tokens%5B1%5D.split('@')%0Apassword = password_tokens%5B0%5D%0Adb_tokens = password_tokens%5B1%5D.split('/')%0Adb_url = db_tokens%5B0%5D%0Adb_name = db_tokens%5B1%5D.split('?')%5B0%5D%0A%0Aconnection = None%0A%0Arows = open(csv_path).read().split('%5Cn')%0Aid_column, status_column = rows%5B0%5D.split(',')%0A%0Atry:%0A    connection = psycopg2.connect(host=db_url, dbname=db_name, user=user_name, password=password)%0A    cursor = connection.cursor()%0A    print 'Starting DB connection...'%0A    for current_row in rows%5B1:%5D:%0A        user_id, status_value = current_row.split(',')%0A%0A        sql_command = %22%22%22%0A        UPDATE users%0A        SET %7B%7D = %7B%7D%0A        WHERE users.id = %7B%7D;%0A        %22%22%22.format(status_column, status_value.upper(), user_id)%0A        cursor.execute(sql_command)%0A%0A        print 'Updating user_id=%7B%7D column=%7B%7D value=%7B%7D'.format(user_id, status_column, status_value)%0A    connection.commit()%0Aexcept psycopg2.DatabaseError:%0A    if connection:%0A        print 'Rolling back...'%0A        connection.rollback()%0Afinally:%0A    if connection:%0A        print 'Closing DB connection...'%0A        connection.close()%0A

Add a script to update users with a CSV