sqlalchemy dataframe titles , genres
This commit is contained in:
45
main.py
45
main.py
@@ -1,23 +1,28 @@
|
||||
|
||||
import os
|
||||
|
||||
import pandas as pd
|
||||
from dotenv import load_dotenv, find_dotenv
|
||||
import psycopg2
|
||||
from sqlalchemy.engine import URL, create_engine
|
||||
|
||||
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()
|
||||
load_dotenv(find_dotenv())
|
||||
|
||||
url = URL.create(
|
||||
drivername="postgresql+psycopg2",
|
||||
username=os.getenv("DATABASE_USERNAME"),
|
||||
password=os.getenv("DATABASE_PASSWORD"),
|
||||
host=os.getenv("DATABASE_IP"),
|
||||
port=int(os.getenv("DATABASE_PORT")),
|
||||
database=os.getenv("DATABASE_NAME"),
|
||||
)
|
||||
|
||||
engine = create_engine(url)
|
||||
|
||||
query = """SELECT title, genres FROM audiobookshelf.ao3;"""
|
||||
|
||||
data = pd.read_sql_query(query, engine)
|
||||
print(data.head())
|
||||
|
||||
# cursor.execute(Query)
|
||||
# row = cursor.fetchone()
|
||||
# while row is not None:
|
||||
# print(row)
|
||||
# row = cursor.fetchone()
|
||||
|
||||
Reference in New Issue
Block a user