aboutsummaryrefslogtreecommitdiffstats
path: root/python/parse_emails.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/parse_emails.py')
-rw-r--r--python/parse_emails.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/python/parse_emails.py b/python/parse_emails.py
index 795e1c2d..11c36c23 100644
--- a/python/parse_emails.py
+++ b/python/parse_emails.py
@@ -2,6 +2,8 @@ import pandas as pd
import re
import os
import pdb
+from db import dbconn
+import psycopg2.sql
from download_emails import update_emails
import datetime
import logging
@@ -330,22 +332,20 @@ def parse_email(email):
subject, email.name))
def write_todb(swaption_stack, index_data):
- sql_str = "INSERT INTO swaption_ref_quotes({}) VALUES({}) ON CONFLICT DO NOTHING"
- cols = index_data.columns
- sql_str = sql_str.format(",".join(cols),
- ",".join(["%s"]* len(cols)))
- from db import dbconn, nan_to_null
- import psycopg2
conn = dbconn('serenitasdb')
- psycopg2.extensions.register_adapter(float, nan_to_null)
+ sql_str = "INSERT INTO swaption_ref_quotes({}) VALUES({}) " \
+ "ON CONFLICT DO NOTHING"
+ cols = index_data.columns
+ sql_str = sql_str.format(sql.SQL(", ").join(sql.Identifier(c) for c in cols),
+ sql.SQL(", ").join(sql.PlaceHolder() * len(cols)))
with conn.cursor() as c:
c.executemany(sql_str, index_data.itertuples(index=False))
conn.commit()
- sql_str = "INSERT INTO swaption_quotes({}) VALUES({}) ON CONFLICT DO NOTHING"
+ sql_str = sql.SQL("INSERT INTO swaption_quotes({}) VALUES({}) ON CONFLICT DO NOTHING")
cols = swaption_stack.columns
- sql_str = sql_str.format(",".join(cols),
- ",".join(["%s"]* len(cols)))
+ sql_str = sql_str.format(sql.SQL(", ").join(sql.Identifier(c) for c in cols),
+ sql.SQL(", ").join(sql.PlaceHolder() * len(cols)))
with conn.cursor() as c:
c.executemany(sql_str, swaption_stack.itertuples(index=False))
conn.commit()