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 automation is key to increasing productivity and reducing the time spent on repetitive tasks. In this article, I'll share how I use Python to automate my freelance workflow, from project management to invoicing.

Step 1: Project Management with Trello and Python

I use Trello to manage my projects, and Python to automate tasks such as creating new boards, lists, and cards. I use the requests library to interact with the Trello API.

import requests

# 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
    }
)
board_id = response.json()["id"]

# Create a new list
list_name = "To-Do"
response = requests.post(
    f"https://api.trello.com/1/lists/",
    params={
        "key": api_key,
        "token": api_token,
        "name": list_name,
        "idBoard": board_id
    }
)
list_id = response.json()["id"]

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

This code creates a new board, list, and card in Trello, saving me time and effort.

Step 2: Time Tracking with Python

I use Python to track my time spent on each project, using the datetime library to calculate the time elapsed.

import datetime

# Start time
start_time = datetime.datetime.now()

# Work on project...

# End time
end_time = datetime.datetime.now()

# Calculate time elapsed
time_elapsed = end_time - start_time

# Save time elapsed to file
with open("time_log.txt", "a") as f:
    f.write(f"Project: {project_name}, Time Elapsed: {time_elapsed}\n")
Enter fullscreen mode Exit fullscreen mode

This code calculates the time spent on a project and saves it to a file, making it easy to track my time and generate invoices.

Step 3: Invoicing with Python

I use Python to generate invoices based on my time log, using the pdfkit library to create a PDF invoice.

import pdfkit

# Load time log
with open("time_log.txt", "r") as f:
    time_log = f.readlines()

# Create invoice
invoice = """
<html>
  <body>
    <h1>Invoice</h1>
    <table>
      <tr>
        <th>Project</th>
        <th>Time Elapsed</th>
      </tr>
"""

for line in time_log:
    project_name, time_elapsed = line.strip().split(", ")
    invoice += f"""
      <tr>
        <td>{project_name}</td>
        <td>{time_elapsed}</td>
      </tr>
"""

invoice += """
    </table>
  </body>
</html>
"""

# Save invoice to PDF
pdfkit.from_string(invoice, "invoice.pdf")
Enter fullscreen mode Exit fullscreen mode

This code generates an invoice based on my time log, saving me time and effort.

Monetization Angle

By automating my freelance workflow with Python, I've been able to increase my productivity and reduce the time spent on repetitive tasks. This has allowed me to take on more clients and projects, increasing my revenue. Additionally, I've been able to

Top comments (0)