Automating My Freelance Workflow with Python: A Step-by-Step Guide
As a freelance developer, I'm always looking for ways to streamline my workflow and increase productivity. One of the most effective tools I've found for achieving this is Python. In this article, I'll walk you through the specific steps I take to automate my freelance workflow using Python, including code examples and a monetization angle.
Step 1: Project Management with Trello and Python
I use Trello to manage my projects, and Python to automate repetitive tasks. For example, I use the Trello API to automatically create new cards for each new project, and assign them to the relevant board and list. Here's an example of how I do this:
import requests
# Set your Trello API credentials
api_key = "your_api_key"
api_secret = "your_api_secret"
# Set the board and list IDs
board_id = "your_board_id"
list_id = "your_list_id"
# Create a new card
def create_card(name, description):
url = f"https://api.trello.com/1/cards"
params = {
"key": api_key,
"token": api_secret,
"name": name,
"desc": description,
"idList": list_id
}
response = requests.post(url, params=params)
return response.json()
# Example usage
new_card = create_card("New Project", "This is a new project")
print(new_card)
This code creates a new card on my Trello board, with the specified name and description.
Step 2: Time Tracking with Python
I use Python to track my time spent on each project, and generate invoices automatically. I use the datetime module to track the start and end times of each task, and the openpyxl library to generate invoices in Excel format. Here's an example of how I do this:
python
import datetime
from openpyxl import Workbook
# Set the project name and rate
project_name = "My Project"
rate = 50 # dollars per hour
# Track the start and end times of each task
def track_time(task_name):
start_time = datetime.datetime.now()
input(f"Press enter when you're finished with {task_name}...")
end_time = datetime.datetime.now()
return start_time, end_time
# Generate an invoice
def generate_invoice(tasks):
wb = Workbook()
ws = wb.active
ws["A1"] = "Task"
ws["B1"] = "Start Time"
ws["C1"] = "End Time"
ws["D1"] = "Duration"
ws["E1"] = "Rate"
ws["F1"] = "Total"
row = 2
for task in tasks:
ws[f"A{row}"] = task["name"]
ws[f"B{row}"] = task["start_time"].strftime("%Y-%m-%d %H:%M:%S")
ws[f"C{row}"] = task["end_time"].strftime("%Y-%m-%d %H:%M:%S")
ws[f"D{row}"] = (task["end_time"] - task["start_time"]).total_seconds() / 3600
ws[f"E{row}"] = rate
ws[f"F{row}"] = (task["end_time"] - task["start_time"]).total_seconds() / 3600 * rate
row += 1
wb.save(f"{project_name}_invoice.xlsx")
# Example usage
tasks = []
while True:
task_name = input("Enter the task name (or 'q' to quit): ")
if task_name.lower() == "q":
break
start_time, end_time = track_time(task













