DEV Community

Caper B
Caper B

Posted on

Automating My Freelance Workflow with Python: A Step-by-Step Guide

Automating My Freelance Workflow with Python: A Step-by-Step Guide

As a freelance developer, I've learned that automation is key to increasing productivity and reducing the time spent on repetitive tasks. In this article, I'll share how I automate my freelance workflow using Python, from project management to invoicing and client communication.

Project Management Automation

I use Trello to manage my projects, and the Trello API to automate tasks such as creating new boards, lists, and cards. I've written a Python script that creates a new board for each project, with lists for "To-Do", "In Progress", and "Done".

import requests

# Trello API credentials
trello_api_key = "YOUR_API_KEY"
trello_api_token = "YOUR_API_TOKEN"

# Create a new board
def create_board(board_name):
    url = f"https://api.trello.com/1/boards/"
    params = {
        "key": trello_api_key,
        "token": trello_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": trello_api_key,
        "token": trello_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": trello_api_key,
        "token": trello_api_token,
        "name": card_name,
        "idList": list_id
    }
    response = requests.post(url, params=params)
    return response.json()

# Example usage:
board_name = "New Project"
board = create_board(board_name)
list_name = "To-Do"
list_id = create_list(board["id"], list_name)["id"]
card_name = "Task 1"
create_card(list_id, card_name)
Enter fullscreen mode Exit fullscreen mode

Time Tracking and Invoicing Automation

I use Harvest to track my time and generate invoices. I've written a Python script that uses the Harvest API to create a new invoice for each project, based on the time tracked.

import requests

# Harvest API credentials
harvest_api_key = "YOUR_API_KEY"
harvest_api_secret = "YOUR_API_SECRET"

# Create a new invoice
def create_invoice(client_id, project_id):
    url = f"https://api.harvestapp.com/v2/invoices"
    headers = {
        "Authorization": f"Bearer {harvest_api_key}",
        "Harvest-Account-Id": "YOUR_ACCOUNT_ID"
    }
    params = {
        "client_id": client_id,
        "project_id": project_id
    }
    response = requests.post(url, headers=headers, params=params)
    return response.json()

# Example usage:
client_id = "12345"
project_id = "67890"
invoice = create_invoice(client_id, project_id)
Enter fullscreen mode Exit fullscreen mode

Client Communication Automation

I use Gmail to communicate with my clients, and the Gmail API to automate tasks such as sending emails and reminders. I've written a Python script that uses the Gmail API to send a weekly update email to each client.


python
import base64
import json
from email.mime.text import MIMEText
from googleapiclient.discovery import build

# Gmail API credentials
gmail_api_key = "YOUR_API_KEY"
gmail_api_secret = "YOUR_API_SECRET"

# Create a new email
def create_email(to, subject, body):
    message = MIMEText(body)
    message["to"] = to
Enter fullscreen mode Exit fullscreen mode

Top comments (0)