aboutsummaryrefslogtreecommitdiffstats
path: root/python/fxgo.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/fxgo.py')
-rw-r--r--python/fxgo.py35
1 files changed, 16 insertions, 19 deletions
diff --git a/python/fxgo.py b/python/fxgo.py
index 57999782..0af3c32f 100644
--- a/python/fxgo.py
+++ b/python/fxgo.py
@@ -3,31 +3,28 @@ from serenitas.utils.exchange import ExchangeMessage
import os
import pandas as pd
from datetime import date
+import io
em = ExchangeMessage()
-emails = em.get_msgs(path=["fxgo"], count=5, subject__contains="Notification")
+emails = em.get_msgs(path=["NYops", "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)
+ output = io.StringIO()
+ with open(dest, "r") as f:
+ for line in f.readlines()[4:]:
+ if "BEGIN PGP SIGNATURE" in line:
+ break
+ 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")
+ os.remove(dest)