Script to convert a TimeEdition App Export to Clockify Format

I migrated from Mac’s amazing “TimeEdition” app made by the same guys that make MAMP.
Unfortunately, their format is not exactly what Clockify expects.

This is the script I used to convert it to the right format:

import csv
from datetime import datetime

# Define a function to convert the date and time format
def convert_datetime(datetime_str):
    dt = datetime.strptime(datetime_str, '%d %b %Y at %H:%M')
    return dt.strftime('%m/%d/%Y'), dt.strftime('%H:%M')

# Input and output filenames
input_filename = input("Origin: ")
output_filename = input("Target: ")

# Open the input CSV file
with open(input_filename, mode='r') as csv_file:
    csv_reader = csv.DictReader(csv_file)
    # Define the new headers for the output CSV
    new_headers = ['Project', 'Client', 'Description', 'Task', 'Email', 'Tags', 'Billable', 'Start Date', 'Start Time', 'Duration (h)']

    # Open the output CSV file and write the new headers
    with open(output_filename, mode='w', newline='') as output_csv_file:
        csv_writer = csv.DictWriter(output_csv_file, fieldnames=new_headers)
        csv_writer.writeheader()

        for row in csv_reader:
            # Split the "Duration" column into hours and minutes
            duration_parts = row['Duration'].split(':')
            hours = int(duration_parts[0])
            minutes = int(duration_parts[1])

            # Convert the "Start" column to date and time
            start_date, start_time = convert_datetime(row['Start'])

            # Format hours and minutes without leading zeros for hours
            formatted_hours = str(hours)
            formatted_minutes = str(minutes).zfill(2)  # Ensure minutes are zero-padded

            # Create a new row in the desired format
            new_row = {
                'Project': row['Project'],
                'Client': row['Client'],
                'Description': row['Activity'],
                'Task': row['Task'],
                'Email': 'YOUR@EMAIL.TLD',
                'Tags': '',
                'Billable': 'yes',
                'Start Date': start_date,
                'Start Time': start_time,
                'Duration (h)': f'{formatted_hours}:{formatted_minutes}'
            }

            # Write the new row to the output CSV file
            csv_writer.writerow(new_row)

print("Conversion completed. New CSV file created:", output_filename)

Make sure to replace YOUR@EMAIL.TLD with your clockify user account email.

Hope this helps someone!