How I Automate My Freelance Workflow with Python
As a freelance developer, I've learned that automating repetitive tasks is key to increasing productivity and earning more. In this article, I'll share how I use Python to streamline my workflow, from project management to invoicing, and how you can do the same.
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'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()
With this script, I can automate the creation of new boards, lists, and cards, saving me time and reducing the risk of human error.
Step 2: Time Tracking with Python
As a freelancer, accurate time tracking is crucial for invoicing clients. I use a Python script to track my time spent on projects, which also helps me identify areas where I can improve my productivity.
import datetime
import time
# Define a function to start tracking time
def start_tracking(project_name):
start_time = datetime.datetime.now()
print(f"Started tracking time for {project_name} at {start_time}")
return start_time
# Define a function to stop tracking time
def stop_tracking(start_time, project_name):
end_time = datetime.datetime.now()
elapsed_time = end_time - start_time
print(f"Stopped tracking time for {project_name} at {end_time}")
print(f"Elapsed time: {elapsed_time}")
return elapsed_time
This script allows me to start and stop tracking time for specific projects, and calculates the elapsed time.
Step 3: Invoicing with Python and PDF
Once I've tracked my time, I use Python to generate invoices in PDF format. I use the fpdf library to create the PDF, and the datetime library to calculate the invoice date.
python
import fpdf
from datetime import datetime
# Define a function to generate an invoice
def generate_invoice(client_name, project_name, hours_worked, rate):
pdf = fpdf.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"Client: {client_name}", ln = True, align = 'L')
pdf.cell(0, 10, txt = f"Project: {project_name}", ln = True, align = 'L')
pdf.cell(0, 10, txt = f"Hours worked: {hours_worked}", ln = True, align = 'L')
pdf.cell(
Top comments (0)