psql ThreadedConnectionPo ol user settings POSTGRESQL_USER password se

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
psql = ThreadedConnectionPool(3, 5, user=settings.POSTGRESQL_USER, password=settings.POSTGRESQL_PASSWORD, host=settings.POSTGRESQL_HOST, dbname=settings.POSTGRESQL_DB, cursor_factory=DictCursor)
try:
conn = psql.getconn()
except:
log.error("Can't get Postgres connection")
return
try:
with conn:
with conn.cursor() as cur:
cur.execute(
"SELECT data FROM bids_v3 WHERE cre_date < %s AND cre_date > %s AND auction_id=%s", (
now, now - datetime.timedelta(days=7), auction_id
))
row = cur.fetchone()
if row:
log.warn("Found bid in Postgres")
data = row["data"]
except Exception as e:
log.warn("Error Postgres")
log.warn(e)
finally:
psql.putconn(conn)