DEV Community

Caper B
Caper B

Posted on

How I Automate My Freelance Workflow with Python

How I Automate My Freelance Workflow with Python

As a freelance developer, I've learned that time is money. The more time I spend on mundane tasks, the less time I have to focus on high-paying projects. That's why I've turned to Python to automate my workflow. In this article, I'll show you how I use Python to streamline my freelance business, from project management to invoicing.

Project Management with Trello and Python

I use Trello to manage my projects, and Python to automate repetitive tasks. For example, I have a board for each client, with lists for different stages of the project (e.g., "To-Do", "In Progress", "Done"). I use the Trello API to create new cards, move cards between lists, and assign due dates.

Here's an example of how I use the requests library to create a new card:

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"

# Card details
card_name = "New Project Task"
card_description = "This is a new task for the project"

# Create a new card
response = requests.post(
    f"https://api.trello.com/1/cards",
    params={
        "key": api_key,
        "token": api_token,
        "name": card_name,
        "desc": card_description,
        "idList": list_id
    }
)

# Check if the card was created successfully
if response.status_code == 200:
    print("Card created successfully!")
else:
    print("Error creating card:", response.text)
Enter fullscreen mode Exit fullscreen mode

This code creates a new card on my Trello board, with the specified name and description. I can then use this card to track the progress of the task.

Time Tracking with Python

As a freelancer, it's essential to track my time accurately to invoice my clients correctly. I use a simple Python script to track my time, which logs the start and end times of each task.

Here's an example of how I use the datetime library to track my time:

import datetime

# Log file
log_file = "time_log.txt"

# Start time
start_time = datetime.datetime.now()
print("Time tracking started at:", start_time)

# Wait for user input to stop time tracking
input("Press Enter to stop time tracking...")

# End time
end_time = datetime.datetime.now()
print("Time tracking stopped at:", end_time)

# Calculate elapsed time
elapsed_time = end_time - start_time
print("Elapsed time:", elapsed_time)

# Log the time to the log file
with open(log_file, "a") as f:
    f.write(f"Start time: {start_time}\n")
    f.write(f"End time: {end_time}\n")
    f.write(f"Elapsed time: {elapsed_time}\n\n")
Enter fullscreen mode Exit fullscreen mode

This script logs the start and end times of each task to a file, which I can then use to generate invoices for my clients.

Invoicing with Python

Speaking of invoices, I use Python to generate invoices automatically based on my time logs. I use the pdfkit library to generate PDF invoices, which I can then send to my clients.

Here's an example of how I use the pdfkit library to generate an invoice:


python
import pdfkit

# Invoice details
invoice_number = "INV001"
client_name = "John Doe"
invoice_date = "2023-02-20"
total_hours = 10
hourly_rate = 50
total_amount = total_hours * hourly_rate

# Generate the invoice HTML
html = f"""
<html>
  <body>
    <h1>Invoice {invoice_number}</h1>

Enter fullscreen mode Exit fullscreen mode

Top comments (0)