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, managing multiple projects and clients can be overwhelming. However, by leveraging the power of Python, I've been able to automate many aspects of my workflow, freeing up more time to focus on high-leverage activities like coding and client acquisition. In this article, I'll share my approach to automating my freelance workflow with Python, including practical steps and code examples.

Step 1: Project Management with Trello and Python

I use Trello to manage my projects and tasks. To automate interactions with Trello, I utilize the requests library in Python to create, update, and delete tasks. Here's an example of how I create a new task:

import requests

# Trello API credentials
API_KEY = 'your_api_key'
API_TOKEN = 'your_api_token'
BOARD_ID = 'your_board_id'
LIST_ID = 'your_list_id'

# Create a new task
def create_task(task_name):
    url = f'https://api.trello.com/1/cards'
    params = {
        'key': API_KEY,
        'token': API_TOKEN,
        'idList': LIST_ID,
        'name': task_name
    }
    response = requests.post(url, params=params)
    if response.status_code == 200:
        print(f'Task {task_name} created successfully')
    else:
        print(f'Failed to create task {task_name}')

# Example usage
create_task('New Task')
Enter fullscreen mode Exit fullscreen mode

This code snippet demonstrates how to create a new task in Trello using Python. You can customize this code to fit your specific needs, such as adding due dates or assigning tasks to specific team members.

Step 2: Time Tracking with Harvest and Python

To track my time spent on projects, I use Harvest. I've created a Python script that integrates with Harvest's API to log my time entries. Here's an example of how I log a new time entry:

import requests

# Harvest API credentials
ACCESS_TOKEN = 'your_access_token'
ACCOUNT_ID = 'your_account_id'
PROJECT_ID = 'your_project_id'
TASK_ID = 'your_task_id'

# Log a new time entry
def log_time_entry(hours, notes):
    url = f'https://api.harvestapp.com/v2/time_entries'
    headers = {
        'Authorization': f'Bearer {ACCESS_TOKEN}',
        'Harvest-Account-Id': ACCOUNT_ID,
        'Content-Type': 'application/json'
    }
    data = {
        'project_id': PROJECT_ID,
        'task_id': TASK_ID,
        'hours': hours,
        'notes': notes
    }
    response = requests.post(url, headers=headers, json=data)
    if response.status_code == 201:
        print(f'Time entry logged successfully')
    else:
        print(f'Failed to log time entry')

# Example usage
log_time_entry(2, 'Worked on new feature')
Enter fullscreen mode Exit fullscreen mode

This code snippet demonstrates how to log a new time entry in Harvest using Python. You can customize this code to fit your specific needs, such as logging time entries for specific projects or tasks.

Step 3: Invoicing with Stripe and Python

To automate my invoicing process, I use Stripe. I've created a Python script that integrates with Stripe's API to generate and send invoices to my clients. Here's an example of how I create a new invoice:


python
import stripe

# Stripe API credentials
STRIPE_SECRET_KEY = 'your_stripe_secret_key'

# Create a new invoice
def create_invoice(client_id, amount):
    stripe.api_key = STRIPE_SECRET_KEY
    invoice = stripe.Invoice.create(
        customer=client_id,
        amount=amount,
        currency='usd',
        description='Freelance services'

Enter fullscreen mode Exit fullscreen mode

Top comments (0)