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.
Introduction to Automation
Automation is the process of using software to perform tasks that would otherwise be done manually. By automating repetitive tasks, I can focus on high-leverage activities like coding, problem-solving, and client communication. Python is an ideal language for automation due to its simplicity, flexibility, and extensive library support.
Step 1: Project Management with Trello and Python
I use Trello to manage my projects, and Python to automate tasks like creating new boards, lists, and cards. The requests library allows me to interact with the Trello API, while the json library helps me parse and generate JSON data.
import requests
import json
# 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}"
)
board_id = response.json()["id"]
# Create a new list
list_name = "To-Do"
response = requests.post(
f"https://api.trello.com/1/lists/?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/?key={api_key}&token={api_token}&name={card_name}&idList={list_id}"
)
Step 2: Time Tracking with Python
Accurate time tracking is essential for freelancers, as it helps us bill clients correctly and optimize our workflow. I use the datetime library to track time spent on tasks, and the csv library to store the data in a CSV file.
import datetime
import csv
# Start time
start_time = datetime.datetime.now()
# Task name
task_name = "Task 1"
# End time
end_time = datetime.datetime.now()
# Calculate elapsed time
elapsed_time = end_time - start_time
# Write to CSV file
with open("time_log.csv", "a", newline="") as csvfile:
fieldnames = ["task_name", "start_time", "end_time", "elapsed_time"]
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
if csvfile.tell() == 0:
writer.writeheader()
writer.writerow({
"task_name": task_name,
"start_time": start_time.strftime("%Y-%m-%d %H:%M:%S"),
"end_time": end_time.strftime("%Y-%m-%d %H:%M:%S"),
"elapsed_time": str(elapsed_time)
})
Step 3: Invoicing with Python and PDF
I use the fpdf library to generate invoices in PDF format, which I can then send to clients. The fpdf library allows me to create custom PDF templates with ease.
python
from fpdf import FPDF
# Create a new PDF
pdf = FPDF()
# Add a page
pdf.add_page()
# Set font and size
pdf.set_font("Arial", size=15)
# Add a cell with text
pdf.cell(200, 10, txt="Invoice for Task 1", ln=True, align="C")
# Add a table
pdf.ln(10)
pdf.set_font("Arial", size=10)
pdf
Top comments (0)