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
34
35
|
import pandas as pd
from io import BytesIO
from pikepdf import Pdf
from . import DAILY_DIR
def load_file(d, fund):
try:
fname = next(
(DAILY_DIR / fund / "JPM_reports").glob(f"CSCFTCSTMT-*-{d:%y%m%d}*.pdf")
)
except StopIteration:
raise FileNotFoundError(f"JPM file not found for date {d}")
return pd.read_excel(fname, skiprows=6, skipfooter=2)
paths = {
# "Serenitas": ["NYops", "Margin Calls JPM"],
"BowdSt": ["BowdoinOps", "Margin JPM"],
}
def download_files(em, count=20, *, fund="BowdSt", **kwargs):
if fund not in paths:
return
emails = em.get_msgs(path=paths[fund], count=count, subject__startswith="909271")
DATA_DIR = DAILY_DIR / fund / "JPM_reports"
for msg in emails:
for attach in msg.attachments:
fname = attach.name
p = DATA_DIR / fname
if not p.exists():
stream = BytesIO(attach.content)
pdf = Pdf.open(stream, password="tm64EO")
pdf.save(p)
|