DEV Community

Golden Alien
Golden Alien

Posted on

🛠️ csv_ledger_merge: Merge Gumroad, Stripe, PayPal CSVs

Merge multiple CSV files from Gumroad, Stripe, and PayPal into a single ledger. This utility uses the csv and argparse modules from the Python standard library. It assumes that the input CSVs have the same structure, with columns for date, description, and amount. The output is a new CSV file containing all transactions from the input files. To use this utility, simply run it from the command line and provide the paths to the input CSVs as arguments. The output CSV will be saved to the current working directory. # Installation To install this utility, save the main.py code to a file and run it using Python. No additional dependencies are required. # Usage Run the utility from the command line like this: python main.py input1.csv input2.csv output.csv Replace input1.csv and input2.csv with the paths to your Gumroad, Stripe, and PayPal CSVs. The output will be saved to output.csv. # Example Use Case Suppose you have three CSV files: gumroad.csv, stripe.csv, and paypal.csv. You can merge them into a single ledger like this: python main.py gumroad.csv stripe.csv paypal.csv merged_ledger.csv

import csv
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('inputs', nargs='+')
parser.add_argument('output')
args = parser.parse_args()

with open(args.output, 'w', newline='') as output_file:
    writer = csv.writer(output_file)
    for input_file in args.inputs:
        with open(input_file, 'r') as file:
            reader = csv.reader(file)
            for row in reader:
                writer.writerow(row)

Enter fullscreen mode Exit fullscreen mode

Top comments (0)