mirror of
https://github.com/migatu/conjurer.git
synced 2026-07-14 21:38:38 +00:00
34 lines
719 B
Python
34 lines
719 B
Python
import netrc
|
|
|
|
import psycopg2
|
|
|
|
NETRC_FILE = ""
|
|
NETRC_FILE = "/home/mtuszowski/.netrc"
|
|
# NETRC_FILE = "/home/pi/.netrc"
|
|
# NETRC_FILE = "C:\\Users\\mtusz\\.netrc"
|
|
|
|
netrc_mod = netrc.netrc(NETRC_FILE)
|
|
REMOTE_HOST_NAME = "sql_localhost"
|
|
authTokens = netrc_mod.authenticators(REMOTE_HOST_NAME)
|
|
|
|
# Connect to your postgres DB
|
|
conn = psycopg2.connect(
|
|
database="scihubdois",
|
|
host="localhost",
|
|
# trunk-ignore(mypy/index)
|
|
user=authTokens[0],
|
|
# trunk-ignore(mypy/index)
|
|
password=authTokens[2],
|
|
port="5432",
|
|
)
|
|
|
|
# Open a cursor to perform database operations
|
|
cur = conn.cursor()
|
|
|
|
# Execute a query
|
|
cur.execute("SELECT * FROM version()")
|
|
|
|
# Retrieve query results
|
|
records = cur.fetchall()
|
|
print(records)
|