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 earning more. In this article, I'll show you how I use Python to streamline my workflow, from project management to invoicing, and how you can do the same.
Project Management Automation
I use Trello to manage my projects, and Python to automate tasks such as creating new boards, lists, and cards. I've written a script that uses the Trello API to create a new board for each project, with pre-defined 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 = "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()["id"]
# Create a new list
def create_list(board_id, list_name):
url = f"https://api.trello.com/1/boards/{board_id}/lists"
params = {
"key": api_key,
"token": api_token,
"name": list_name
}
response = requests.post(url, params=params)
return response.json()["id"]
# 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()["id"]
# Example usage
board_id = create_board("New Project")
list_id = create_list(board_id, "To-Do")
create_card(list_id, "Task 1")
Time Tracking Automation
I use Harvest to track my time, and Python to automate tasks such as creating new projects, tasks, and logging time. I've written a script that uses the Harvest API to create a new project and task, and log time for each task.
python
import requests
# Harvest API credentials
api_key = "your_api_key"
api_secret = "your_api_secret"
# Create a new project
def create_project(project_name):
url = "https://api.harvestapp.com/v2/projects"
headers = {
"Authorization": f"Bearer {api_key}",
"Harvest-Account-Id": "your_account_id"
}
data = {
"project": {
"name": project_name
}
}
response = requests.post(url, headers=headers, json=data)
return response.json()["project"]["id"]
# Create a new task
def create_task(project_id, task_name):
url = f"https://api.harvestapp.com/v2/projects/{project_id}/task_assignments"
headers = {
"Authorization": f"Bearer {api_key}",
"Harvest-Account-Id": "your_account_id"
}
data = {
"task_assignment": {
"task": {
"name": task_name
}
}
}
response = requests.post(url, headers=headers, json=data)
return response.json()["task_assignment"]["task"]["id"]
# Log time for a task
def log_time(task_id, hours):
url = f"https://api.harvestapp.com/v2/time_entries"
headers = {
"Authorization": f"Bearer {api_key}",
"Harvest-Account-Id": "your_account_id"
}
data = {
"time_entry": {
"project_id":
Top comments (0)