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, I've learned that automating repetitive tasks is key to increasing productivity and earning more. In this article, I'll show you 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

# 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/?key={api_key}&token={api_token}&name={board_name}"
)
print(response.json())
Enter fullscreen mode Exit fullscreen mode

This code creates a new board with the specified name. I can then use this board to manage my project, and automate tasks such as creating new lists and cards.

Step 2: Time Tracking with Python

I use Python to track my time spent on each project. I create a simple script that prompts me to enter the project name and the time spent on it.

import datetime

# Define a dictionary to store project names and time spent
projects = {}

def track_time():
    project_name = input("Enter project name: ")
    time_spent = input("Enter time spent (in hours): ")
    if project_name in projects:
        projects[project_name] += float(time_spent)
    else:
        projects[project_name] = float(time_spent)
    print(f"Time tracked for {project_name}: {projects[project_name]} hours")

while True:
    track_time()
Enter fullscreen mode Exit fullscreen mode

This script allows me to easily track my time spent on each project, and store the data in a dictionary. I can then use this data to generate invoices and track my productivity.

Step 3: Invoicing with Python and PDF

I use Python to generate invoices in PDF format. I use the fpdf library to create the PDF, and the datetime library to get the current date.

from fpdf import FPDF
import datetime

# Define a function to generate an invoice
def generate_invoice(project_name, time_spent, rate):
    pdf = FPDF()
    pdf.add_page()
    pdf.set_font("Arial", size = 15)
    pdf.cell(200, 10, txt = "Invoice", ln = True, align = 'C')
    pdf.ln(10)
    pdf.set_font("Arial", size = 10)
    pdf.cell(0, 10, txt = f"Project: {project_name}", ln = True, align = 'L')
    pdf.cell(0, 10, txt = f"Time spent: {time_spent} hours", ln = True, align = 'L')
    pdf.cell(0, 10, txt = f"Rate: ${rate}/hour", ln = True, align = 'L')
    pdf.cell(0, 10, txt = f"Total: ${time_spent * rate}", ln = True, align = 'L')
    pdf.output("invoice.pdf")

# Example usage
project_name = "New Project"
time_spent = 10
rate = 50
generate_invoice(project_name, time_spent, rate)
Enter fullscreen mode Exit fullscreen mode

This code generates an invoice in PDF format, with the project name, time spent, rate, and total amount. I can then send this invoice to my client, and get paid for my work.

Monetization Angle

By automating my freelance workflow with Python, I'm able to increase my productivity and earn more.

Top comments (0)