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 efficiency. In this article, I'll share 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 task assignment using Python and the Trello API:
import requests
# Trello API credentials
trello_key = "your_trello_key"
trello_token = "your_trello_token"
board_id = "your_board_id"
list_id = "your_list_id"
# Create a new task
def create_task(task_name, task_description):
url = f"https://api.trello.com/1/cards"
params = {
"key": trello_key,
"token": trello_token,
"name": task_name,
"desc": task_description,
"idList": list_id
}
response = requests.post(url, params=params)
return response.json()
# Example usage
task_name = "New Task"
task_description = "This is a new task"
create_task(task_name, task_description)
This script creates a new task on my Trello board with the specified name and description.
Time Tracking Automation
I use the datetime and time modules in Python to track the time spent on each task. Here's an example of how I automate time tracking:
import datetime
import time
# Start time
start_time = datetime.datetime.now()
# Task name
task_name = "New Task"
# Start timer
def start_timer(task_name):
print(f"Starting timer for {task_name}")
start_time = datetime.datetime.now()
return start_time
# Stop timer
def stop_timer(start_time, task_name):
print(f"Stopping timer for {task_name}")
end_time = datetime.datetime.now()
elapsed_time = end_time - start_time
print(f"Elapsed time: {elapsed_time}")
return elapsed_time
# Example usage
start_time = start_timer(task_name)
time.sleep(5) # Simulate work
elapsed_time = stop_timer(start_time, task_name)
This script starts a timer when I begin working on a task and stops it when I'm finished. The elapsed time is then printed to the console.
Invoicing Automation
I use the pdfkit library in Python to generate invoices automatically. Here's an example of how I automate invoicing:
python
import pdfkit
from datetime import date
# Invoice data
invoice_number = "INV001"
invoice_date = date.today()
client_name = "John Doe"
client_address = "123 Main St"
service_description = "Software development services"
service_hours = 10
service_rate = 100
# Generate invoice
def generate_invoice(invoice_number, invoice_date, client_name, client_address, service_description, service_hours, service_rate):
html = f"""
<html>
<body>
<h1>Invoice {invoice_number}</h1>
<p>Date: {invoice_date}</p>
<p>Client: {client_name}</p>
<p>Address: {client_address}</p>
<p>Service: {service_description}</p>
<p>Hours: {service_hours}</p>
<p>Rate: ${service_rate}/hour</p>
<p>Total: ${service_hours * service_rate}</p>
</body>
</html>
"""
options = {
"page-size": "Letter",
"margin-top": "0.75in",
"margin-right": "0.75in",
"margin-bottom": "0
Top comments (0)