updates to structure

This commit is contained in:
2024-03-08 14:35:12 -07:00
parent 953ee6f1c2
commit 79764c9d1c
4 changed files with 47 additions and 1 deletions

View File

@@ -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 <input_file>")
sys.exit(1)
input_file = sys.argv[1]
auto_convert(input_file)

View File

@@ -1,3 +1,5 @@
#!/usr/bin/env python3
from datetime import datetime, timedelta from datetime import datetime, timedelta
def calculate_reach_date(current_hours, max_hours, hours_added_bi_weekly): 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 # Output
print(f"Current date: {datetime.now().strftime('%Y-%m-%d')}") 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')}") print(f"You will reach the maximum hours on: {reach_date.strftime('%Y-%m-%d')}")