How I Automate My Freelance Workflow with Python
As a freelance developer, I've learned that automation is key to increasing productivity and efficiency. In this article, I'll share how I use Python to automate my freelance workflow, from project management to invoicing.
Introduction to Automation
Automation is the process of using software to perform repetitive tasks, freeing up time for more important things. As a freelancer, I wear many hats - developer, project manager, accountant, and more. By automating certain tasks, I can focus on high-leverage activities like coding and client acquisition.
Step 1: Project Management with Trello and Python
I use Trello to manage my projects, and Python to automate tasks like creating new boards and lists. Here's an example of how I use the Trello API with Python:
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
}
)
# Get the new board ID
board_id = response.json()["id"]
# Create new lists
lists = ["To-Do", "In Progress", "Done"]
for list_name in lists:
response = requests.post(
f"https://api.trello.com/1/lists?",
params={
"key": api_key,
"token": api_token,
"name": list_name,
"idBoard": board_id
}
)
This code creates a new Trello board and adds three lists: To-Do, In Progress, and Done.
Step 2: Time Tracking with Python
I use a simple Python script to track my time spent on projects. Here's an example:
import datetime
# Start time
start_time = datetime.datetime.now()
# Do some work...
# Stop time
stop_time = datetime.datetime.now()
# Calculate elapsed time
elapsed_time = stop_time - start_time
# Log the time
with open("time_log.txt", "a") as f:
f.write(f"{elapsed_time} - {start_time} - {stop_time}\n")
This code logs the time spent on a task to a file called time_log.txt.
Step 3: Invoicing with Python and PDF
I use Python to generate invoices in PDF format. Here's an example:
import fpdf
# Invoice data
invoice_number = "INV001"
client_name = "John Doe"
project_name = "New Project"
hours_worked = 10
hourly_rate = 100
# Create a PDF
pdf = fpdf.FPDF()
# Add a page
pdf.add_page()
# Set font
pdf.set_font("Arial", size=15)
# Add invoice data
pdf.cell(200, 10, txt="Invoice", ln=True, align='C')
pdf.cell(200, 10, txt=invoice_number, ln=True, align='C')
pdf.cell(200, 10, txt=client_name, ln=True, align='C')
pdf.cell(200, 10, txt=project_name, ln=True, align='C')
pdf.cell(200, 10, txt=f"Hours worked: {hours_worked}", ln=True, align='C')
pdf.cell(200, 10, txt=f"Hourly rate: ${hourly_rate}", ln=True, align='C')
pdf.cell(200, 10, txt=f"Total: ${hours_worked * hourly_rate}", ln=True, align='C')
# Save the PDF
pdf.output("invoice.pdf")
This code generates a PDF invoice with
Top comments (0)