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 relationships. In this article, I'll walk you through the exact steps I take to automate my freelance workflow with Python, including code examples and monetization strategies.

Step 1: Project Management with Trello and Python

To manage my projects, I use Trello, a popular project management tool. However, manually updating boards and cards can be time-consuming. To automate this process, I use the Trello API and Python's requests library. Here's an example code snippet that creates a new card on my board:

import requests

# Trello API credentials
api_key = "your_api_key"
api_token = "your_api_token"
board_id = "your_board_id"
list_id = "your_list_id"

# Create a new card
card_name = "New Project"
card_description = "This is a new project"

url = f"https://api.trello.com/1/cards"
params = {
    "key": api_key,
    "token": api_token,
    "name": card_name,
    "desc": card_description,
    "idList": list_id
}

response = requests.post(url, params=params)

if response.status_code == 200:
    print("Card created successfully")
else:
    print("Error creating card")
Enter fullscreen mode Exit fullscreen mode

This code snippet creates a new card on my Trello board with the specified name and description.

Step 2: Time Tracking with Python

Accurate time tracking is crucial for freelance developers. To automate time tracking, I use the datetime library and a simple script that logs my work hours to a CSV file. Here's an example code snippet:

import datetime
import csv

# Log work hours to a CSV file
def log_work_hours(project_name, hours_worked):
    with open("work_hours.csv", "a", newline="") as csvfile:
        fieldnames = ["project_name", "hours_worked", "date"]
        writer = csv.DictWriter(csvfile, fieldnames=fieldnames)

        if csvfile.tell() == 0:
            writer.writeheader()

        writer.writerow({
            "project_name": project_name,
            "hours_worked": hours_worked,
            "date": datetime.date.today()
        })

# Example usage
log_work_hours("Project X", 5)
Enter fullscreen mode Exit fullscreen mode

This code snippet logs my work hours to a CSV file, making it easy to track my time and generate invoices.

Step 3: Invoicing with Python and PDF Generation

To automate invoicing, I use the fpdf library to generate PDF invoices. Here's an example code snippet that generates a PDF invoice:


python
from fpdf import FPDF

# Generate a PDF invoice
def generate_invoice(project_name, hours_worked, rate):
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Arial", size=15)
    pdf.cell(200, 10, txt="Invoice for " + project_name, ln=True, align="C")

    pdf.set_font("Arial", size=10)
    pdf.cell(0, 10, txt="Project Name: " + project_name, ln=True, align="L")
    pdf.cell(0, 10, txt="Hours Worked: " + str(hours_worked), ln=True, align="L")
    pdf.cell(0, 10, txt="Rate: $" + str(rate), ln=True, align="L")
    pdf.cell(0, 10, txt="Total: $" + str(hours_worked * rate), ln=True, align="L")


Enter fullscreen mode Exit fullscreen mode

Top comments (0)