DEV Community

Caper B
Caper B

Posted on

How I Automate My Freelance Workflow with Python: Boosting Productivity and Earnings

How I Automate My Freelance Workflow with Python: Boosting Productivity and Earnings

===========================================================

As a freelance developer, I've learned that automation is key to increasing productivity, reducing manual labor, and ultimately, growing my business. In this article, I'll share how I use Python to automate my freelance workflow, from project management to invoicing, and provide you with practical steps to do the same.

Step 1: Project Management with Trello and Python


I use Trello to manage my projects, and with the help of Python, I can automate tasks such as:

  • Creating new boards and lists
  • Moving cards between lists
  • Assigning due dates and labels

Here's an example of how I use the requests library to interact with the Trello API:

import requests

# Set your Trello API credentials
api_key = "your_api_key"
api_token = "your_api_token"

# Create a new board
board_name = "New Project"
response = requests.post(
    f"https://api.trello.com/1/boards/",
    params={
        "key": api_key,
        "token": api_token,
        "name": board_name
    }
)
print(response.json())
Enter fullscreen mode Exit fullscreen mode

This code creates a new Trello board with the specified name. You can then use the requests library to create lists, cards, and comments, and automate your project management workflow.

Step 2: Time Tracking with Python


Accurate time tracking is essential for freelancers, as it helps you bill clients correctly and optimize your workflow. I use a Python script to track my time spent on projects:

import datetime
import json

# Set your time tracking data file
data_file = "time_tracking.json"

# Start a new timer
def start_timer(project_name):
    start_time = datetime.datetime.now()
    with open(data_file, "r+") as f:
        data = json.load(f)
        data[project_name] = {"start_time": start_time.isoformat()}
        f.seek(0)
        json.dump(data, f)
        f.truncate()

# Stop the timer
def stop_timer(project_name):
    end_time = datetime.datetime.now()
    with open(data_file, "r+") as f:
        data = json.load(f)
        start_time = datetime.datetime.fromisoformat(data[project_name]["start_time"])
        elapsed_time = end_time - start_time
        data[project_name] = {"elapsed_time": elapsed_time.total_seconds() / 3600}
        f.seek(0)
        json.dump(data, f)
        f.truncate()

# Example usage:
start_timer("Project X")
# Work on Project X...
stop_timer("Project X")
Enter fullscreen mode Exit fullscreen mode

This script allows you to start and stop a timer for a specific project, and saves the elapsed time to a JSON file. You can then use this data to generate invoices and track your productivity.

Step 3: Invoicing with Python and PDF Generation


Once you've tracked your time, you need to generate invoices for your clients. I use a Python script to create invoices in PDF format:


python
import pdfkit
from jinja2 import Template

# Set your invoice template
template = Template("""
<html>
  <body>
    <h1>Invoice for {{ project_name }}</h1>
    <p>Hours worked: {{ hours_worked }}</p>
    <p>Rate: ${{ rate }}</p>
    <p>Total: ${{ total }}</p>
  </body>
</html>
""")

# Generate an invoice
def generate_invoice(project_name, hours_worked, rate):
    total = hours_worked * rate
    html = template.render(
        project_name=project_name,
        hours_worked=hours_worked,
        rate=rate,
        total
Enter fullscreen mode Exit fullscreen mode

Top comments (0)