blob: bd817377b8fb3cdcc630a141d0c4dfe969e2e062 (
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
34
35
36
37
38
39
40
41
42
43
44
45
|
from serenitas.utils.env import DAILY_DIR
from serenitas.utils.remote import SftpClient
import datetime
import pytz
from stat import S_ISREG
import csv
def download_files(date):
downloaded_files = []
sftp = SftpClient.from_creds("bbg")
dst = DAILY_DIR / f"{date:%Y-%m-%d}" / "bbg_tickets"
if not dst.exists():
dst.mkdir()
est = pytz.timezone("US/Eastern")
src = ""
for f in sftp.client.listdir_iter():
if S_ISREG(f.st_mode):
local_file = dst / f.filename
modification_time = datetime.datetime.fromtimestamp(
f.st_mtime, tz=datetime.timezone.utc
).astimezone(est)
if not local_file.exists() and (modification_time.date() == date):
sftp.client.get(f"{src}/{f.filename}", localpath=local_file)
downloaded_files.append(local_file)
return downloaded_files
def cdx_booking_process(path):
reader = csv.DictReader(open(path))
for csvdict in reader:
breakpoint()
pass
def book_trades(date):
downloaded_files = download_files(date)
if downloaded_files:
for f in downloaded_files:
if "CDX" in f.name:
cdx_booking_process(f)
if __name__ == "__main__":
book_trades(datetime.date(2022, 2, 4))
|