aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--python/parse_emails.py27
1 files changed, 11 insertions, 16 deletions
diff --git a/python/parse_emails.py b/python/parse_emails.py
index fab7d5d4..bd39d353 100644
--- a/python/parse_emails.py
+++ b/python/parse_emails.py
@@ -333,22 +333,17 @@ def parse_email(email):
def write_todb(swaption_stack, index_data):
conn = dbconn('serenitasdb')
- 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 = sql.SQL("INSERT INTO swaption_quotes({}) VALUES({}) ON CONFLICT DO NOTHING")
- cols = swaption_stack.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, swaption_stack.itertuples(index=False))
- conn.commit()
+ query = sql.SQL("INSERT INTO {}({}) VALUES({}) " \
+ "ON CONFLICT DO NOTHING")
+ for df, table in zip([index_data, swaption_stack],
+ ["swaption_ref_quotes", "swaption_quotes"]):
+ cols = df.columns
+ sql_str = query.format(sql.Identifier(table),
+ 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, df.itertuples(index=False))
+ conn.commit()
conn.close()
def get_email_list(date):