import os import psycopg2 os.environ['DB_USER'] = 'kheops' os.environ['DB_PASSWORD'] = '3Wq4se8ahy0do79xrputgz&' os.environ['DB_HOST'] = '51.159.25.78' os.environ['DB_NAME'] = 'agilix' os.environ['DB_PORT'] = '19114' db_name = os.environ['DB_NAME'] db_user = os.environ['DB_USER'] db_host = os.environ['DB_HOST'] db_password = os.environ['DB_PASSWORD'] db_port = os.environ['DB_PORT'] conn = psycopg2.connect(f"dbname={db_name} user={db_user} host={db_host} password={db_password} port={db_port}") conn.autocommit = True def insert_score(question, response, score, comment): try: conn = psycopg2.connect(f"dbname={db_name} user={db_user} host={db_host} password={db_password} port={db_port}") conn.autocommit = True cur = conn.cursor() # Define the SQL query to insert a record into the score table insert_query = """ INSERT INTO score (question, response, score, comment) VALUES (%s, %s,%s, %s); """ # Data to be inserted (example data) data_to_insert = (question, response, score, comment) # Execute the query with the provided data cur.execute(insert_query, data_to_insert) conn.commit() cur.close() return 'feedback sent' except: return 'Error' def show_table(): cur = conn.cursor() # Define the SQL query to select all records from the score table select_query = "SELECT * FROM score;" # Execute the query cur.execute(select_query) # Fetch all the rows from the result of the query rows = cur.fetchall() # Print the rows for row in rows: print(row) # insert_score(conn, 1, 'test') # show_table(conn)