DEV Community

Caper B
Caper B

Posted on

Automating My Freelance Workflow with Python: A Step-by-Step Guide

Automating My Freelance Workflow with Python: A Step-by-Step Guide

As a freelance developer, managing multiple projects and clients can be overwhelming. However, by leveraging the power of Python, I've been able to automate many tasks, freeing up more time to focus on high-leverage activities like coding and client acquisition. In this article, I'll walk you through the exact steps I take to automate my freelance workflow using Python.

Step 1: Project Initialization and Setup

When I start a new project, I create a new directory with the project name and initialize a new Git repository. I also create a README.md file to store project notes and a requirements.txt file to manage dependencies. I've automated this process using a Python script:

import os
import subprocess

def init_project(project_name):
    # Create a new directory
    os.makedirs(project_name, exist_ok=True)

    # Initialize a new Git repository
    subprocess.run(["git", "init"], cwd=project_name)

    # Create a README.md file
    with open(os.path.join(project_name, "README.md"), "w") as f:
        f.write("# " + project_name + "\n")

    # Create a requirements.txt file
    with open(os.path.join(project_name, "requirements.txt"), "w") as f:
        f.write("")

# Example usage
init_project("my_new_project")
Enter fullscreen mode Exit fullscreen mode

This script saves me around 5 minutes per project, which may not seem like a lot, but it adds up over time.

Step 2: Time Tracking and Invoicing

As a freelancer, it's essential to track time spent on projects to invoice clients accurately. I use a Python script to track my time and generate invoices:

import datetime
import pandas as pd

def track_time(project_name, hours_worked):
    # Load existing time tracking data
    try:
        time_data = pd.read_csv("time_tracking.csv")
    except FileNotFoundError:
        time_data = pd.DataFrame(columns=["Project", "Date", "Hours Worked"])

    # Add new time tracking data
    new_data = pd.DataFrame({"Project": [project_name], "Date": [datetime.date.today()], "Hours Worked": [hours_worked]})
    time_data = pd.concat([time_data, new_data])

    # Save updated time tracking data
    time_data.to_csv("time_tracking.csv", index=False)

def generate_invoice(project_name, client_name, hourly_rate):
    # Load time tracking data for the project
    time_data = pd.read_csv("time_tracking.csv")
    project_data = time_data[time_data["Project"] == project_name]

    # Calculate total hours worked and invoice amount
    total_hours_worked = project_data["Hours Worked"].sum()
    invoice_amount = total_hours_worked * hourly_rate

    # Generate invoice
    with open("invoice.txt", "w") as f:
        f.write("Invoice for " + project_name + "\n")
        f.write("Client: " + client_name + "\n")
        f.write("Hours Worked: " + str(total_hours_worked) + "\n")
        f.write("Hourly Rate: $" + str(hourly_rate) + "\n")
        f.write("Invoice Amount: $" + str(invoice_amount) + "\n")

# Example usage
track_time("my_project", 5)
generate_invoice("my_project", "John Doe", 100)
Enter fullscreen mode Exit fullscreen mode

This script saves me around 30 minutes per invoice, which is a significant time savings.

Step 3: Client Communication and Onboarding

When I start working with a new client, I need to send them a welcome email with information about our working agreement, communication channels, and project scope. I've automated this process using a Python script:


python
import sm
Enter fullscreen mode Exit fullscreen mode

Top comments (0)