From 2425a4cf7c69034bce63f75e68cb442e7e31ff0a Mon Sep 17 00:00:00 2001 From: Jon Michael Aanes Date: Mon, 24 Mar 2025 20:47:24 +0100 Subject: [PATCH] Init html data foramt --- html_data_format/__init__.py | 1 + html_data_format/__main__.py | 58 ++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 html_data_format/__init__.py create mode 100644 html_data_format/__main__.py diff --git a/html_data_format/__init__.py b/html_data_format/__init__.py new file mode 100644 index 0000000..a81fdcd --- /dev/null +++ b/html_data_format/__init__.py @@ -0,0 +1 @@ +"""# HTML-Data Formatting""" diff --git a/html_data_format/__main__.py b/html_data_format/__main__.py new file mode 100644 index 0000000..1e94864 --- /dev/null +++ b/html_data_format/__main__.py @@ -0,0 +1,58 @@ +import argparse +import logging +from pathlib import Path +from typing import Any + +from personal_data.csv_import import load_csv_file + +logger = logging.getLogger(__name__) + + +def parse_arguments(): + parser = argparse.ArgumentParser() + parser.add_argument( + 'file', + type=Path, + ) + parser.add_argument( + 'output_file', + type=Path, + ) + + return parser.parse_args() + + +def format_data_to_html(data: list[dict[str, Any]], mode: str = 'latest') -> str: + sample = data[-1] + + l = [] + l.append('') + l.append('') + + for k, v in sample.items(): + l.append(f'
{k}: {v}
') + + l.append('') + l.append('') + + return ''.join(l) + + +def main(): + logging.basicConfig() + logging.getLogger('git_time_tracker').setLevel('INFO') + + args = parse_arguments() + + # Load data + data = load_csv_file(args.file) + print(data) + + html = format_data_to_html(data) + + with open(args.output_file, 'w') as f: + f.write(html) + + +if __name__ == '__main__': + main()