aboutsummaryrefslogtreecommitdiffstats
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/citco.py42
1 files changed, 32 insertions, 10 deletions
diff --git a/python/citco.py b/python/citco.py
index 68a7830d..1a30955e 100644
--- a/python/citco.py
+++ b/python/citco.py
@@ -3,7 +3,7 @@ from serenitas.utils.env import DAILY_DIR
from serenitas.utils.db import dawn_engine, dbconn
from serenitas.utils.remote import SftpClient
import datetime
-from serenitas.analytics.dates import prev_business_day
+from serenitas.analytics.dates import prev_business_day, next_business_day
import re
@@ -23,30 +23,52 @@ def load_citco_report(fdir):
return df
-if __name__ == "__main__":
- #### argparse WIP
- date = datetime.date.today()
- workdate = prev_business_day(date)
- ####
- reports_dir = DAILY_DIR / str(date) / "Reports"
+def download_reports(cob):
+ reports_dir = DAILY_DIR / str(next_business_day(cob)) / "Reports"
reports_dir.mkdir(exist_ok=True, parents=True)
sftp = SftpClient.from_creds("citco")
citco_files = [
filename
for filename in sftp.client.listdir("/outgoing")
if "SPOS4X_INNOCAP" in filename
- if get_ped(filename)[0] <= workdate
+ if get_ped(filename)[0] == cob
]
f = max(citco_files, key=get_ped)
+ if not f:
+ return
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")
+
+
+def load_reports(cob):
+ reports_dir = DAILY_DIR / str(next_business_day(cob)) / "Reports"
+ dest = reports_dir / "Valuation_Report_ISOSEL.csv"
+ if not dest.exists():
+ # Early exit, file not there
+ return
+ df = load_citco_report(dest)
conn = dbconn("dawndb")
with conn.cursor() as c:
c.execute(
"DELETE from citco_reports where period_end_date =%s",
- (get_ped(f)[0],),
+ (cob,),
)
conn.commit()
df.to_sql("citco_reports", dawn_engine, if_exists="append", index=False)
+
+
+if __name__ == "__main__":
+ import argparse
+
+ parser = argparse.ArgumentParser()
+ parser.add_argument(
+ "cob",
+ nargs="?",
+ type=datetime.date.fromisoformat,
+ default=prev_business_day(datetime.date.today()),
+ help="close of business",
+ )
+ args = parser.parse_args()
+ download_reports(args.cob)
+ load_reports(args.cob)