DEV Community

Caper B
Caper B

Posted on

How I Automate My Freelance Workflow with Python

How I Automate My Freelance Workflow with Python

As a freelance developer, I've learned that automation is key to increasing productivity and reducing the time spent on mundane tasks. In this article, I'll share how I use Python to automate my freelance workflow, from project management to invoicing, and how it's helped me boost my earnings.

Project Management Automation

I use a combination of Python scripts and APIs to automate my project management workflow. For example, I use the Trello API to create new boards and lists for each project, and the GitHub API to create new repositories and invite collaborators.

import requests

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

# Create a new Trello board
def create_trello_board(board_name):
    url = f"https://api.trello.com/1/boards/"
    params = {
        "name": board_name,
        "key": trello_api_key,
        "token": trello_api_token
    }
    response = requests.post(url, params=params)
    return response.json()["id"]

# Create a new GitHub repository
def create_github_repo(repo_name):
    url = "https://api.github.com/repos"
    params = {
        "name": repo_name,
        "description": "New repository",
        "private": True
    }
    headers = {
        "Authorization": f"Bearer YOUR_GITHUB_TOKEN"
    }
    response = requests.post(url, json=params, headers=headers)
    return response.json()["id"]
Enter fullscreen mode Exit fullscreen mode

Time Tracking Automation

I use the Toggl API to track my time spent on each project. I've written a Python script that automatically starts and stops the timer based on my Git commit history.

import requests
import datetime

# Toggl API credentials
toggl_api_token = "YOUR_API_TOKEN"

# Start the Toggl timer
def start_toggl_timer(project_id):
    url = f"https://api.toggl.com/reports/v8/details"
    params = {
        "user_agent": "freelance_tracker",
        "workspace_id": "YOUR_WORKSPACE_ID",
        "project_id": project_id,
        "since": datetime.date.today().strftime("%Y-%m-%d"),
        "until": datetime.date.today().strftime("%Y-%m-%d")
    }
    headers = {
        "Authorization": f"Bearer {toggl_api_token}"
    }
    response = requests.get(url, params=params, headers=headers)
    return response.json()["data"]

# Stop the Toggl timer
def stop_toggl_timer(project_id):
    url = f"https://api.toggl.com/reports/v8/details"
    params = {
        "user_agent": "freelance_tracker",
        "workspace_id": "YOUR_WORKSPACE_ID",
        "project_id": project_id,
        "since": datetime.date.today().strftime("%Y-%m-%d"),
        "until": datetime.date.today().strftime("%Y-%m-%d")
    }
    headers = {
        "Authorization": f"Bearer {toggl_api_token}"
    }
    response = requests.get(url, params=params, headers=headers)
    return response.json()["data"]
Enter fullscreen mode Exit fullscreen mode

Invoicing Automation

I use the Stripe API to generate invoices for my clients. I've written a Python script that automatically generates an invoice based on my Toggl time tracking data.


python
import requests

# Stripe API credentials
stripe_api_key = "YOUR_API_KEY"

# Generate an invoice
def generate_invoice(client_id, project_id):
    url = "https://api.stripe.com/v1/invoices"
    params = {
        "customer": client_id,
        "billing_address": {
            "name": "John Doe",
            "address": {
                "line1":
Enter fullscreen mode Exit fullscreen mode

Top comments (0)