diff options
Diffstat (limited to 'python/fxgo.py')
| -rw-r--r-- | python/fxgo.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/python/fxgo.py b/python/fxgo.py new file mode 100644 index 00000000..57999782 --- /dev/null +++ b/python/fxgo.py @@ -0,0 +1,33 @@ +from serenitas.utils.env import DAILY_DIR +from serenitas.utils.exchange import ExchangeMessage +import os +import pandas as pd +from datetime import date + +em = ExchangeMessage() + +emails = em.get_msgs(path=["fxgo"], count=5, subject__contains="Notification") + +unmodified_files = [] +for msg in emails: + for attach in msg.attachments: + dest = DAILY_DIR / "fxgo" / attach.name + dest.write_bytes(attach.content) + unmodified_files.append(dest) + +test_file = DAILY_DIR / "fxgo" / "test.csv" +for unmodified_file in unmodified_files: + with open(unmodified_file, "r") as f, open(test_file, "w") as test: + for line in f.readlines()[4:]: + if "BEGIN PGP SIGNATURE" in line: + break + else: + test.write(line) + df = pd.read_csv(test_file) + counterparty_name = df["Bank1DealingCode"][0] + msgtype = df["MsgType"][0] + date = df["DateOfDeal"][0] + time = df["TimeOfDeal"][0] + df.to_csv(DAILY_DIR / "fxgo" / f"{date}_{counterparty_name}_{msgtype}_{time}.csv") + os.remove(unmodified_file) + os.remove(test_file) |
