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 automating repetitive tasks is key to increasing productivity and earning more. In this article, I'll share how I use Python to automate my freelance workflow, from project management to invoicing, and provide you with practical steps to 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. Here's an example of how I use the Trello API to create a new board:

import requests

# Trello API credentials
api_key = "your_api_key"
api_token = "your_api_token"

# Create a new board
board_name = "New Project"
response = requests.post(
    f"https://api.trello.com/1/boards/",
    params={
        "key": api_key,
        "token": api_token,
        "name": board_name
    }
)

# Get the board ID
board_id = response.json()["id"]

print(f"Board created: {board_name} ({board_id})")
Enter fullscreen mode Exit fullscreen mode

This script creates a new board with the specified name and prints the board ID.

Time Tracking Automation

I use Toggl to track my time, and Python to automate tasks such as starting and stopping timers. Here's an example of how I use the Toggl API to start a new timer:

import requests

# Toggl API credentials
api_token = "your_api_token"

# Start a new timer
project_name = "New Project"
task_name = "Development"
response = requests.post(
    "https://api.toggl.com/reports/v8/details",
    headers={
        "Authorization": f"Basic {api_token}",
        "Content-Type": "application/json"
    },
    json={
        "user_agent": "my_app",
        "description": task_name,
        "project": project_name,
        "tags": ["development"]
    }
)

# Get the timer ID
timer_id = response.json()["data"]["items"][0]["id"]

print(f"Timer started: {task_name} ({timer_id})")
Enter fullscreen mode Exit fullscreen mode

This script starts a new timer with the specified project and task names and prints the timer ID.

Invoicing Automation

I use PayPal to send invoices, and Python to automate tasks such as generating invoices and sending reminders. Here's an example of how I use the PayPal API to generate an invoice:


python
import requests

# PayPal API credentials
client_id = "your_client_id"
client_secret = "your_client_secret"

# Generate an invoice
invoice_name = "New Invoice"
amount = 100.0
response = requests.post(
    "https://api.paypal.com/v1/invoicing/invoices",
    headers={
        "Authorization": f"Bearer {client_id}",
        "Content-Type": "application/json"
    },
    json={
        "invoice": {
            "merchant_info": {
                "name": "My Company",
                "address": {
                    "line1": "123 Main St",
                    "city": "Anytown",
                    "state": "CA",
                    "zip": "12345",
                    "country_code": "US"
                }
            },
            "billing_info": [
                {
                    "name": "John Doe",
                    "address": {
                        "line1": "456 Elm St",
                        "city": "Othertown",
                        "state": "NY",
                        "zip": "67890",
                        "country_code": "US"
                    }
                }
            ],
            "items": [
                {
                    "name": invoice_name,
                    "quantity": 1,
                    "unit_price": {
                        "currency": "USD",
                        "value": amount
                    }
                }
            ]
        }
    }
)

Enter fullscreen mode Exit fullscreen mode

Top comments (0)