blob: 579997820266b37be46f213f97b583c2bd2dd11b (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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)
|