How I Automate My Freelance Workflow with Python
As a freelance developer, I've learned that automating repetitive tasks is crucial to increasing productivity and delivering high-quality work to clients. 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 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
api_key = "your_api_key"
api_token = "your_api_token"
board_id = "your_board_id"
list_id = "your_list_id"
# Assign task to card
def assign_task(card_id, task_name):
url = f"https://api.trello.com/1/cards/{card_id}/actions/comments"
headers = {
"Authorization": f"Bearer {api_token}",
"Content-Type": "application/json"
}
data = {
"text": task_name
}
response = requests.post(url, headers=headers, json=data)
if response.status_code == 200:
print(f"Task '{task_name}' assigned to card {card_id}")
else:
print(f"Error assigning task: {response.text}")
# Example usage
card_id = "your_card_id"
task_name = "Implement feature X"
assign_task(card_id, task_name)
This script assigns a task to a specific Trello card using the Trello API. I can schedule this script to run daily or weekly to ensure that tasks are assigned and updated automatically.
Time Tracking Automation
Accurate time tracking is essential for invoicing clients. I use a Python script to track my work hours and generate reports:
import datetime
import csv
# Log work hours
def log_work_hours(project_name, start_time, end_time):
work_hours = end_time - start_time
with open("work_hours.log", "a", newline="") as csvfile:
fieldnames = ["project_name", "start_time", "end_time", "work_hours"]
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
if csvfile.tell() == 0:
writer.writeheader()
writer.writerow({
"project_name": project_name,
"start_time": start_time.strftime("%Y-%m-%d %H:%M"),
"end_time": end_time.strftime("%Y-%m-%d %H:%M"),
"work_hours": str(work_hours)
})
# Example usage
project_name = "Client X Project"
start_time = datetime.datetime(2023, 3, 1, 9, 0)
end_time = datetime.datetime(2023, 3, 1, 17, 0)
log_work_hours(project_name, start_time, end_time)
This script logs work hours to a CSV file, which I can later use to generate invoices.
Invoicing Automation
I use a Python script to generate invoices based on the work hours logged:
python
import csv
import datetime
# Generate invoice
def generate_invoice(project_name, client_name, work_hours, hourly_rate):
invoice_date = datetime.date.today()
invoice_number = f"INV{invoice_date.strftime('%Y%m%d')}"
invoice_amount = work_hours * hourly_rate
with open(f"{invoice_number}.pdf", "w") as invoice_file:
invoice_file.write(f"Invoice {invoice_number}\n")
invoice_file.write(f"Project: {project_name}\n")
invoice_file.write(f"Client: {client_name}\n")
invoice_file.write(f"Work Hours: {work_hours}\n")
invoice_file.write(f"Hourly Rate: ${hourly_rate:.2f}\n")
invoice
Top comments (0)