diff --git a/projects/conversion_csv_json/convert.py b/projects/conversion_csv_json/convert.py new file mode 100644 index 0000000..dd33a77 --- /dev/null +++ b/projects/conversion_csv_json/convert.py @@ -0,0 +1,44 @@ +import csv +import json +import sys +import os + +def csv_to_json(csv_filepath, json_filepath): + data = [] + with open(csv_filepath, encoding='utf-8') as csvf: + csv_reader = csv.DictReader(csvf) + for row in csv_reader: + data.append(row) + with open(json_filepath, 'w', encoding='utf-8') as jsonf: + jsonf.write(json.dumps(data, indent=4)) + +def json_to_csv(json_filepath, csv_filepath): + with open(json_filepath, 'r', encoding='utf-8') as jsonf: + data = json.load(jsonf) + if data: + with open(csv_filepath, 'w', encoding='utf-8', newline='') as csvf: + writer = csv.DictWriter(csvf, fieldnames=data[0].keys()) + writer.writeheader() + writer.writerows(data) + +def auto_convert(input_file): + file_name, file_extension = os.path.splitext(input_file) + if file_extension.lower() == ".csv": + output_file = f"{file_name}.json" + csv_to_json(input_file, output_file) + print(f"Converted {input_file} to {output_file}") + elif file_extension.lower() == ".json": + output_file = f"{file_name}.csv" + json_to_csv(input_file, output_file) + print(f"Converted {input_file} to {output_file}") + else: + print("Unsupported file format. Please provide a .csv or .json file.") + sys.exit(1) + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("Usage: python convert.py ") + sys.exit(1) + input_file = sys.argv[1] + auto_convert(input_file) + diff --git a/projects/conversion_csv_json/data/input.csv b/projects/conversion_csv_json/data/input.csv new file mode 100644 index 0000000..e69de29 diff --git a/projects/conversion_csv_json/data/output.json b/projects/conversion_csv_json/data/output.json new file mode 100644 index 0000000..e69de29 diff --git a/projects/dev/pto_countdown/main.py b/projects/dev/pto_countdown/main.py index 970f193..99afb60 100644 --- a/projects/dev/pto_countdown/main.py +++ b/projects/dev/pto_countdown/main.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + from datetime import datetime, timedelta def calculate_reach_date(current_hours, max_hours, hours_added_bi_weekly): @@ -40,4 +42,4 @@ reach_date = calculate_reach_date(current_hours, MAX_HOURS, HOURS_ADDED_BI_WEEKL # Output print(f"Current date: {datetime.now().strftime('%Y-%m-%d')}") -print(f"You will reach the maximum hours on: {reach_date.strftime('%Y-%m-%d')}") \ No newline at end of file +print(f"You will reach the maximum hours on: {reach_date.strftime('%Y-%m-%d')}")