|
|
|
|
@ -16,6 +16,7 @@ Pathlike = pathlib.Path | str
@@ -16,6 +16,7 @@ Pathlike = pathlib.Path | str
|
|
|
|
|
|
|
|
|
|
WINHOME = pathlib.Path("/mnt/c/Users/Holgi/") |
|
|
|
|
DESKTOP = WINHOME / "Desktop" |
|
|
|
|
OBSIDIAN = WINHOME / "Documents" / "Obsidian Vault" |
|
|
|
|
|
|
|
|
|
TODAY = datetime.now().strftime("%Y-%m-%d") |
|
|
|
|
|
|
|
|
|
@ -255,8 +256,7 @@ def _create_text_stub(path: Pathlike, *, content: str = None) -> None:
@@ -255,8 +256,7 @@ def _create_text_stub(path: Pathlike, *, content: str = None) -> None:
|
|
|
|
|
path.write_text(content) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _fill_pre_payments_form(destination_path: Pathlike) -> PrePayments: |
|
|
|
|
pre_payments = _read_pre_payments() |
|
|
|
|
def _fill_pre_payments_form(pre_payments:PrePayments, destination_path: Pathlike) -> Pathlike: |
|
|
|
|
|
|
|
|
|
print(f"Projekt: {pre_payments.project}") |
|
|
|
|
print(f"Kostenstelle: {pre_payments.cost_center}") |
|
|
|
|
@ -276,29 +276,76 @@ def _fill_pre_payments_form(destination_path: Pathlike) -> PrePayments:
@@ -276,29 +276,76 @@ def _fill_pre_payments_form(destination_path: Pathlike) -> PrePayments:
|
|
|
|
|
filled = form.fill(pre_payments.to_form_data(), flatten=False) |
|
|
|
|
pathlib.Path(destination_path).write_bytes(filled.read()) |
|
|
|
|
|
|
|
|
|
return pre_payments |
|
|
|
|
return destination_path |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _search_travel_notes(travel_nr:str) -> Pathlike: |
|
|
|
|
folders = [item for item in OBSIDIAN.iterdir() if item.is_dir()] |
|
|
|
|
travel_folders = sorted(item for item in folders if item.stem.lower().startswith("dr")) |
|
|
|
|
|
|
|
|
|
for folder in travel_folders: |
|
|
|
|
files = [item for item in folder.iterdir() if item.is_file] |
|
|
|
|
mardowns = [item for item in files if item.suffix.lower() == ".md"] |
|
|
|
|
for markdown_file in mardowns: |
|
|
|
|
if travel_nr in markdown_file.read_text(): |
|
|
|
|
print(f"found markown note '{markdown_file.name}' for travel nr {travel_nr}") |
|
|
|
|
return markdown_file |
|
|
|
|
sys.exit( |
|
|
|
|
f"Could not find an obsidian note for travel nr '{travel_nr}'" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _search_travel(travel_nr) -> TravelInfo: |
|
|
|
|
markdown_file = _search_travel_notes(travel_nr) |
|
|
|
|
if not markdown_file: |
|
|
|
|
return None |
|
|
|
|
result = {key:"" for key in ("traveller", "date", "destination")} |
|
|
|
|
for line in markdown_file.read_text().splitlines(): |
|
|
|
|
if line.lower().startswith("traveller"): |
|
|
|
|
result["traveller"] = _parse_obsidian_traveller(line) |
|
|
|
|
if line.lower().startswith("start"): |
|
|
|
|
result["date"] = _parse_obsidian_value(line) |
|
|
|
|
if line.lower().startswith("destination"): |
|
|
|
|
result["destination"] = _parse_obsidian_value(line) |
|
|
|
|
for key, value in result.items(): |
|
|
|
|
if value: |
|
|
|
|
print(f"found {key} '{value}' in markdown note") |
|
|
|
|
else: |
|
|
|
|
sys.exit(f"Could not find {key} in note '{markdown_file}'") |
|
|
|
|
return _complete_travel_info(result["traveller"], result["date"], result["destination"]) |
|
|
|
|
|
|
|
|
|
def _parse_obsidian_traveller(raw_data:str) -> str: |
|
|
|
|
link = _parse_obsidian_value(raw_data) |
|
|
|
|
for character in '"[@/]': |
|
|
|
|
link = link.replace(character, "") |
|
|
|
|
_, _, last_name = link.rpartition(" ") |
|
|
|
|
return last_name |
|
|
|
|
|
|
|
|
|
def _parse_obsidian_value(raw_data:str) -> str: |
|
|
|
|
_, _, value = raw_data.partition(":") |
|
|
|
|
return value.strip() |
|
|
|
|
|
|
|
|
|
@click.command() |
|
|
|
|
def fill_prepayment_form(): |
|
|
|
|
pre_payments = _read_pre_payments() |
|
|
|
|
destination_path = DESKTOP / f"{TODAY} UK-Abschlag.pdf" |
|
|
|
|
_fill_pre_payments_form(destination_path) |
|
|
|
|
_fill_pre_payments_form(pre_payments, destination_path) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@click.command() |
|
|
|
|
@click.option("-l", "--search_last_name", prompt=True, required=True) |
|
|
|
|
@click.option("-d", "--iso_date", prompt=True, required=True) |
|
|
|
|
@click.option("-p", "--place", prompt=True, required=True) |
|
|
|
|
def final_payment(search_last_name: str, iso_date: str, place: str): |
|
|
|
|
def final_payment(): |
|
|
|
|
payments = _read_pre_payments() |
|
|
|
|
print(f"found travel number {payments.travel_nr}") |
|
|
|
|
info = _search_travel(payments.travel_nr) |
|
|
|
|
|
|
|
|
|
print("---") |
|
|
|
|
info = _complete_travel_info(search_last_name, iso_date, place) |
|
|
|
|
print(f"Name: {info.first_last}") |
|
|
|
|
|
|
|
|
|
folder = DESKTOP / f"{info.travel_name} (abgerechnet)" |
|
|
|
|
folder.mkdir() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
destination_path = folder / f"{TODAY} {info.travel_short}, UK-Abschlag.pdf" |
|
|
|
|
payments = _fill_pre_payments_form(destination_path) |
|
|
|
|
_fill_pre_payments_form(payments, destination_path) |
|
|
|
|
|
|
|
|
|
rk_path = folder / f"DATE {info.travel_short}, Reisekostenabrechnung.txt" |
|
|
|
|
_create_text_stub(rk_path) |
|
|
|
|
|