How I Automate My Freelance Workflow with Python
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 this is Python. In this article, I'll show you how I use Python to automate my freelance workflow, from project management to invoicing.
Setting up a Project Management System
The first step in automating my workflow is to set up a project management system. I use a combination of Trello and Python to manage my projects. I've created a Python script that interacts with the Trello API to create new boards, lists, and cards.
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/"
params = {
"key": api_key,
"token": api_token,
"name": board_name
}
response = requests.post(url, params=params)
return response.json()
# Create a new list
def create_list(board_id, list_name):
url = f"https://api.trello.com/1/lists"
params = {
"key": api_key,
"token": api_token,
"name": list_name,
"idBoard": board_id
}
response = requests.post(url, params=params)
return response.json()
# Create a new card
def create_card(list_id, card_name):
url = f"https://api.trello.com/1/cards"
params = {
"key": api_key,
"token": api_token,
"name": card_name,
"idList": list_id
}
response = requests.post(url, params=params)
return response.json()
Automating Time Tracking
Time tracking is an essential part of freelance work. I use a Python script to track my time spent on each project. The script uses the datetime module to track the start and end times of each work session.
import datetime
# Create a new time entry
def create_time_entry(project_name, start_time, end_time):
time_entry = {
"project": project_name,
"start_time": start_time,
"end_time": end_time
}
return time_entry
# Calculate the total time spent on a project
def calculate_total_time(project_name, time_entries):
total_time = 0
for time_entry in time_entries:
if time_entry["project"] == project_name:
start_time = datetime.datetime.strptime(time_entry["start_time"], "%Y-%m-%d %H:%M:%S")
end_time = datetime.datetime.strptime(time_entry["end_time"], "%Y-%m-%d %H:%M:%S")
total_time += (end_time - start_time).total_seconds() / 3600
return total_time
Generating Invoices
Once I've completed a project, I need to generate an invoice for the client. I use a Python script to generate invoices based on the time entries and project rates.
python
import pandas as pd
# Create a new invoice
def create_invoice(project_name, time_entries, project_rate):
invoice = {
"project": project_name,
"time_entries": time_entries,
"project_rate": project_rate
}
return invoice
# Calculate the total amount due
def calculate_total_amount(invoice):
total_amount = 0
for time_entry in invoice["time_entries"]:
total_amount += time_entry["hours"] * invoice["project_rate"]
return total_amount
# Generate an invoice PDF
def generate_invoice_pdf(invoice):
df = pd.DataFrame({
"Date": [time_entry["
Top comments (0)