How I Automate My Freelance Workflow with Python
As a freelancer, I've learned that automation is key to increasing productivity and earning more. In this article, I'll show you how I use Python to automate my freelance workflow, from project management to invoicing.
Project Management Automation
I use a combination of Python scripts and tools like Trello and GitHub to manage my projects. Here's an example of how I automate project creation:
import requests
import json
# Trello API credentials
trello_key = "your_trello_key"
trello_token = "your_trello_token"
# Create a new Trello board
def create_board(board_name):
url = f"https://api.trello.com/1/boards/"
params = {
"key": trello_key,
"token": trello_token,
"name": board_name
}
response = requests.post(url, params=params)
return response.json()
# Create a new Trello board for a project
project_name = "New Project"
board_id = create_board(project_name)["id"]
print(f"Board created: {board_id}")
This script creates a new Trello board for each project, allowing me to easily organize and manage my tasks.
Time Tracking Automation
Accurate time tracking is crucial for freelancers. I use a Python script to track my time spent on each project:
import datetime
import json
# Time tracking data
time_data = {}
# Start tracking time
def start_tracking(project_name):
start_time = datetime.datetime.now()
time_data[project_name] = start_time
print(f"Time tracking started for {project_name}")
# Stop tracking time
def stop_tracking(project_name):
end_time = datetime.datetime.now()
start_time = time_data[project_name]
elapsed_time = end_time - start_time
print(f"Time tracking stopped for {project_name}. Elapsed time: {elapsed_time}")
return elapsed_time
# Example usage
project_name = "New Project"
start_tracking(project_name)
# Work on the project...
elapsed_time = stop_tracking(project_name)
print(f"Elapsed time: {elapsed_time}")
This script allows me to easily start and stop tracking time for each project, making it simple to generate accurate invoices.
Invoicing Automation
I use a Python script to generate invoices based on my time tracking data:
import json
import pdfkit
# Invoice data
invoice_data = {
"project_name": "New Project",
"client_name": "John Doe",
"hours_worked": 10,
"hourly_rate": 50
}
# Generate invoice
def generate_invoice(invoice_data):
# Calculate total amount
total_amount = invoice_data["hours_worked"] * invoice_data["hourly_rate"]
# Create invoice HTML
html = f"""
<h1>Invoice for {invoice_data["project_name"]}</h1>
<p>Client: {invoice_data["client_name"]}</p>
<p>Hours worked: {invoice_data["hours_worked"]}</p>
<p>Hourly rate: ${invoice_data["hourly_rate"]}</p>
<p>Total amount: ${total_amount}</p>
"""
# Convert HTML to PDF
pdfkit.from_string(html, "invoice.pdf")
print("Invoice generated: invoice.pdf")
# Example usage
generate_invoice(invoice_data)
This script generates a professional-looking invoice based on my time tracking data, making it easy to send to clients.
Monetization Angle
By automating my freelance workflow, I've been able to increase my productivity and earn more. I've also been able to offer higher-value services to my clients, such as project management and time tracking, which has led to
Top comments (0)