sql titles , genres

This commit is contained in:
CC
2026-09-01 22:35:05 +01:00
parent 45ade682c3
commit 4ebc24f21b
3 changed files with 122 additions and 20 deletions

41
main.py
View File

@@ -1,22 +1,23 @@
import os
from dotenv import load_dotenv, find_dotenv
import psycopg2
connection = psycopg2.connect(
user="postgres",
host="192.168.10.102",
port="5433",
database="abs"
)
try:
cursor = connection.cursor()
cursor.execute("SELECT version();")
record = cursor.fetchone()
print("You are connected to - ", record, "\n")
except (Exception, psycopg2.Error) as error:
print("Error while connecting to PostgreSQL", error)
finally:
if connection:
cursor.close()
connection.close()
print("PostgreSQL connection is closed")
load_dotenv(find_dotenv())
connection = psycopg2.connect(
user = os.getenv("DATABASE_USERNAME"),
password = os.getenv("DATABASE_PASSWORD"),
host = os.getenv("DATABASE_IP"),
port = os.getenv("DATABASE_PORT"),
database = os.getenv("DATABASE_NAME")
)
cursor = connection.cursor()
Query = """SELECT title, genres FROM audiobookshelf.ao3;"""
cursor.execute(Query)
row = cursor.fetchone()
while row is not None:
print(row)
row = cursor.fetchone()