How I Automate My Freelance Workflow with Python
As a freelance developer, I've learned that streamlining my workflow is crucial to increasing productivity and delivering high-quality results to clients. In this article, I'll share how I use Python to automate repetitive tasks, manage projects, and even generate invoices.
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've created a Python script that uses the Trello API to automate these tasks.
import requests
# Trello API credentials
api_key = "YOUR_API_KEY"
api_token = "YOUR_API_TOKEN"
# Create a new board
def create_board(board_name):
url = f"https://api.trello.com/1/boards/?key={api_key}&token={api_token}&name={board_name}"
response = requests.post(url)
return response.json()
# Create a new list
def create_list(board_id, list_name):
url = f"https://api.trello.com/1/lists/?key={api_key}&token={api_token}&name={list_name}&idBoard={board_id}"
response = requests.post(url)
return response.json()
# Create a new card
def create_card(list_id, card_name):
url = f"https://api.trello.com/1/cards/?key={api_key}&token={api_token}&name={card_name}&idList={list_id}"
response = requests.post(url)
return response.json()
These functions allow me to automate the creation of new boards, lists, and cards, saving me time and reducing manual errors.
Time Tracking with Python
I use a Python script to track my time spent on projects. The script uses the datetime module to calculate the time spent on each task.
import datetime
# Start time
start_time = datetime.datetime.now()
# End time
end_time = datetime.datetime.now()
# Calculate time spent
time_spent = end_time - start_time
# Log time spent
def log_time(task_name, time_spent):
with open("time_log.txt", "a") as f:
f.write(f"{task_name}: {time_spent}\n")
# Example usage
task_name = "Project X"
start_time = datetime.datetime.now()
# Do some work...
end_time = datetime.datetime.now()
time_spent = end_time - start_time
log_time(task_name, time_spent)
This script allows me to track my time spent on each task and log it to a file, making it easy to generate invoices and calculate my hourly rate.
Invoicing with Python
I use a Python script to generate invoices based on my time log. The script uses the fpdf library to create a PDF invoice.
python
from fpdf import FPDF
# Create a PDF invoice
def create_invoice(client_name, project_name, time_spent, hourly_rate):
pdf = FPDF()
pdf.add_page()
pdf.set_font("Arial", size=15)
pdf.cell(200, 10, txt="Invoice", ln=True, align='C')
pdf.set_font("Arial", size=10)
pdf.cell(200, 10, txt=f"Client: {client_name}", ln=True, align='L')
pdf.cell(200, 10, txt=f"Project: {project_name}", ln=True, align='L')
pdf.cell(200, 10, txt=f"Time Spent: {time_spent}", ln=True, align='L')
pdf.cell(200, 10, txt=f"Hourly Rate: ${hourly_rate}", ln=True, align='L')
pdf.output("invoice.pdf")
# Example usage
client_name = "John Doe"
project_name = "
Top comments (0)