In [1]:
import os
import settings
import pandas as pd
In [2]:
filings = pd.read_csv(os.path.join(settings.data_dir, "filings.csv"))
In [3]:
sql_template = """
SELECT *
FROM "calaccess_processed_form460scheduleeitem"
WHERE filing_id IN ({})
"""
In [5]:
sql = sql_template.format(", ".join(map(str, filings.calaccess_filing_id)))
In [6]:
sched_e = pd.read_sql_query(sql, settings.db_connection)
In [10]:
refunds = sched_e[sched_e.payment_code == 'RFD']
In [12]:
refunds.to_csv(os.path.join(settings.data_dir, "refunds.csv"), index=False)
In [14]:
recent_filings = pd.read_csv(os.path.join(settings.data_dir, "filings-2016.csv"))
In [15]:
recent_sql = sql_template.format(", ".join(map(str, recent_filings.calaccess_filing_id)))
In [16]:
recent_sched_e = pd.read_sql_query(recent_sql, settings.db_connection)
In [17]:
recent_refunds = recent_sched_e[recent_sched_e.payment_code == 'RFD']
In [18]:
recent_refunds.to_csv(os.path.join(settings.data_dir, "refunds-2016.csv"), index=False)