diff options
Diffstat (limited to 'python/fxgo.py')
| -rw-r--r-- | python/fxgo.py | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/python/fxgo.py b/python/fxgo.py index 9b3935e5..7ceef1a6 100644 --- a/python/fxgo.py +++ b/python/fxgo.py @@ -1,30 +1,35 @@ +from exchangelib import FileAttachment from serenitas.utils.env import DAILY_DIR from serenitas.utils.exchange import ExchangeMessage -import os -import pandas as pd -from datetime import date -import io +from io import BytesIO em = ExchangeMessage() emails = em.get_msgs(path=["NYops", "FXgo"], count=5, subject__contains="Notification") -unmodified_files = [] for msg in emails: + cp = msg.subject.split("/", 1)[0] for attach in msg.attachments: - dest = DAILY_DIR / "fxgo" / attach.name - dest.write_bytes(attach.content) - output = io.StringIO() - with open(dest, "r") as f: - for line in f.readlines()[4:]: - if "BEGIN PGP SIGNATURE" in line: - break + if isinstance(attach, FileAttachment): + with attach.fp as fh: + for _ in range(4): + next(fh) + buf = BytesIO() + # header line + buf.write(next(fh)) + line = next(fh) + if b"DEAL" in line: + msg_type = "DEAL" + elif b"ALOC" in line: + msg_type = "ALOC" else: - output.write(line) - output.seek(0) - df = pd.read_csv(output) - cp, msgtype, date, time = df[ - ["Bank1DealingCode", "MsgType", "DateOfDeal", "TimeOfDeal"] - ].loc[0] - df.to_csv(DAILY_DIR / "fxgo" / f"{date}_{cp}_{msgtype}_{time}.csv", index=False) - os.remove(dest) + raise ValueError("Unknown message type") + fname = f"{msg.last_modified_time:%Y%m%d}_{cp}_{msg_type}_{msg.last_modified_time:%H%M%S}.csv" + dest = DAILY_DIR / "fxgo" / fname + if dest.exists(): + continue + buf.write(line) + buf.writelines(iter(fh.readline, b"-----BEGIN PGP SIGNATURE-----\n")) + + with dest.open("wb") as fh: + fh.write(buf.getbuffer()) |
