aboutsummaryrefslogtreecommitdiffstats
path: root/python/citco.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/citco.py')
-rw-r--r--python/citco.py29
1 files changed, 23 insertions, 6 deletions
diff --git a/python/citco.py b/python/citco.py
index cf8aaebe..68a7830d 100644
--- a/python/citco.py
+++ b/python/citco.py
@@ -4,6 +4,13 @@ from serenitas.utils.db import dawn_engine, dbconn
from serenitas.utils.remote import SftpClient
import datetime
from serenitas.analytics.dates import prev_business_day
+import re
+
+
+def get_ped(s):
+ if m := re.search("IM.([\d.]+)\.", s):
+ dt = datetime.datetime.strptime(m.group(1), "%Y%m%d.%H%M%S")
+ return dt.date(), dt.time()
def load_citco_report(fdir):
@@ -12,24 +19,34 @@ def load_citco_report(fdir):
df.columns = df.columns.str.lower()
df.columns = df.columns.str.replace(" ", "_")
df["period_end_date"] = pd.to_datetime(df["period_end_date"], format="%Y%m%d")
+ df["knowledge_date"] = pd.to_datetime(df["period_end_date"], format="%Y%m%d")
return df
if __name__ == "__main__":
+ #### argparse WIP
date = datetime.date.today()
+ workdate = prev_business_day(date)
+ ####
reports_dir = DAILY_DIR / str(date) / "Reports"
+ reports_dir.mkdir(exist_ok=True, parents=True)
sftp = SftpClient.from_creds("citco")
- for f in sftp.client.listdir("/outgoing"):
- if "SPOS4X" in f:
- sftp.client.get(
- f"/outgoing/{f}", localpath=reports_dir / f"Valuation_Report_ISOSEL.csv"
- )
+ citco_files = [
+ filename
+ for filename in sftp.client.listdir("/outgoing")
+ if "SPOS4X_INNOCAP" in filename
+ if get_ped(filename)[0] <= workdate
+ ]
+ f = max(citco_files, key=get_ped)
+ sftp.client.get(
+ f"/outgoing/{f}", localpath=reports_dir / f"Valuation_Report_ISOSEL.csv"
+ )
df = load_citco_report(reports_dir / f"Valuation_Report_ISOSEL.csv")
conn = dbconn("dawndb")
with conn.cursor() as c:
c.execute(
"DELETE from citco_reports where period_end_date =%s",
- (prev_business_day(date),),
+ (get_ped(f)[0],),
)
conn.commit()
df.to_sql("citco_reports", dawn_engine, if_exists="append", index=False)