aboutsummaryrefslogtreecommitdiffstats
path: root/python/report_ops/misc.py
blob: 72bf03990004437d6ed9b2f4dd1f0ef8b1d8d0f8 (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
import pathlib
import datetime
from serenitas.utils.env import DAILY_DIR


def get_dir(workdate: datetime.date, archived=True) -> pathlib.Path:
    p = DAILY_DIR / str(workdate) / "Reports"
    if not p.exists() and archived:
        p = (
            DAILY_DIR
            / str(workdate.year)
            / f"{workdate:%Y_%m}"
            / str(workdate)
            / "Reports"
        )
    return p


def dt_from_fname(f, dt_format="%Y%m%d%H%M"):
    return datetime.datetime.strptime(
        f.name.removesuffix(".csv").removesuffix(".xlsx").rsplit("_")[-1], dt_format
    )


def dt_from_citco(filename, file_tag, dt_format):
    return datetime.datetime.strptime(
        filename.removesuffix(".csv").removeprefix(file_tag), dt_format
    )