from report_ops.sma import build_position_file import argparse from serenitas.utils.remote import Client from serenitas.utils.exchange import ExchangeMessage, FileAttachment from report_ops.misc import _recipients, _cc_recipients import datetime from serenitas.analytics.dates import prev_business_day def main(cob, fund, upload): buf, dest = build_position_file( cob, fund, ) if upload: client = Client.from_creds("hm_globeop") client.put(buf, dest.name) em = ExchangeMessage() em.send_email( subject=f"Position_files for Bowdoin Street as of {cob}", body=f"Please see monthend positions for Bowdoin Street as of {cob}. They have been uploaded to the SFTP as well.", to_recipients=_recipients[fund], cc_recipients=_cc_recipients[fund], reply_to=_cc_recipients[fund], attach=[FileAttachment(name=dest.name, content=buf)], ) parser = argparse.ArgumentParser( description="Generate position files for Bowdoin Street" ) parser.add_argument( "date", nargs="?", type=datetime.date.fromisoformat, default=prev_business_day((datetime.date.today().replace(day=1))), ) parser.add_argument( "--no-upload", "-n", action="store_true", default=False, help="uploads to globeop", ) args = parser.parse_args() if ( not prev_business_day(datetime.date.today()) == args.date and not args.no_upload ): # We only want to upload if the previous business day was monthend pass else: main(args.date, "BOWDST", not args.no_upload)