Automating My Freelance Workflow with Python: A Step-by-Step Guide
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
# Set Trello API credentials
api_key = "YOUR_API_KEY"
api_secret = "YOUR_API_SECRET"
# Create a new board
board_name = "New Project"
response = requests.post(
f"https://api.trello.com/1/boards/",
params={
"key": api_key,
"token": api_secret,
"name": board_name
}
)
# Get the board ID
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_secret,
"name": list_name,
"idBoard": board_id
}
)
# Get the list 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_secret,
"name": card_name,
"idList": list_id
}
)
This code creates a new board, list, and card in Trello, allowing me to automate the project setup process.
Step 2: Time Tracking with Python
I use a Python script to track my time spent on each task. I use the datetime library to log the start and end times of each task.
import datetime
# Set the task name
task_name = "Task 1"
# Log the start time
start_time = datetime.datetime.now()
print(f"Started {task_name} at {start_time}")
# Simulate work
import time
time.sleep(60)
# Log the end time
end_time = datetime.datetime.now()
print(f"Finished {task_name} at {end_time}")
# Calculate the time spent
time_spent = end_time - start_time
print(f"Time spent on {task_name}: {time_spent}")
This code logs the start and end times of each task, allowing me to track my time spent on each project.
Step 3: Invoicing with Python
I use a Python script to generate invoices for my clients. I use the pdfkit library to generate PDF invoices.
import pdfkit
# Set the invoice details
invoice_number = "INV001"
client_name = "John Doe"
project_name = "New Project"
total_hours = 10
hourly_rate = 50
# Generate the invoice HTML
html = f"""
<html>
<body>
<h1>Invoice {invoice_number}</h1>
<p>Client: {client_name}</p>
<p>Project: {project_name}</p>
<p>Total Hours: {total_hours}</p>
<p>Hourly Rate: {hourly_rate}</p>
<p>Total: {total_hours * hourly_rate}</p>
</body>
</html>
"""
# Generate the PDF invoice
pdfkit.from_string(html, "invoice.pdf")
This code generates a PDF invoice with the client's details, project name, total hours, and hourly rate.
Monetization Angle
By automating my freelance workflow with Python, I
Top comments (0)