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 repetitive tasks. In this article, I'll share how I use Python to automate my freelance workflow, from project management to invoicing, and explore the monetization opportunities that come with it.

Project Management Automation

I use the github API to automate my project management workflow. I've created a Python script that automatically creates a new repository for each new project, sets up the necessary labels and milestones, and assigns the project to my GitHub account.

import requests

def create_repository(project_name):
    url = "https://api.github.com/user/repos"
    headers = {
        "Authorization": "Bearer YOUR_GITHUB_TOKEN",
        "Content-Type": "application/json"
    }
    data = {
        "name": project_name,
        "description": "",
        "private": True
    }
    response = requests.post(url, headers=headers, json=data)
    return response.json()

# Example usage
project_name = "new-project"
repository = create_repository(project_name)
print(repository["html_url"])
Enter fullscreen mode Exit fullscreen mode

Time Tracking Automation

I use the toggl API to automate my time tracking workflow. I've created a Python script that automatically starts a new timer when I start working on a project, and stops the timer when I'm finished.

import requests
import time

def start_timer(project_id):
    url = "https://api.toggl.com/reports/v8/details"
    headers = {
        "Authorization": "Basic YOUR_TOGGL_TOKEN",
        "Content-Type": "application/json"
    }
    data = {
        "user_id": YOUR_TOGGL_USER_ID,
        "project_id": project_id,
        "description": "Working on project"
    }
    response = requests.post(url, headers=headers, json=data)
    return response.json()

def stop_timer(entry_id):
    url = f"https://api.toggl.com/reports/v8/details/{entry_id}/stop"
    headers = {
        "Authorization": "Basic YOUR_TOGGL_TOKEN",
        "Content-Type": "application/json"
    }
    response = requests.put(url, headers=headers)
    return response.json()

# Example usage
project_id = YOUR_TOGGL_PROJECT_ID
entry_id = start_timer(project_id)["data"]["id"]
time.sleep(3600)  # Work for 1 hour
stop_timer(entry_id)
Enter fullscreen mode Exit fullscreen mode

Invoicing Automation

I use the stripe API to automate my invoicing workflow. I've created a Python script that automatically generates an invoice for each client at the end of the month, and sends it to them via email.

import stripe

stripe.api_key = "YOUR_STRIPE_SECRET_KEY"

def create_invoice(client_id, amount):
    invoice = stripe.Invoice.create(
        customer=client_id,
        amount=amount,
        currency="usd",
        description="Monthly invoice"
    )
    return invoice

def send_invoice(invoice_id):
    invoice = stripe.Invoice.retrieve(invoice_id)
    client_email = invoice.customer_email
    # Send email to client with invoice link
    print(f"Sent invoice to {client_email}")

# Example usage
client_id = "cu_client_id"
amount = 1000
invoice_id = create_invoice(client_id, amount)["id"]
send_invoice(invoice_id)
Enter fullscreen mode Exit fullscreen mode

Monetization Opportunities

By automating my freelance workflow with Python, I've been able to increase my productivity and reduce the time spent on repetitive tasks. This has allowed me to take on more clients and projects, and increase my earnings. Additionally, I've been able to offer my automation services to other freelancers and businesses, providing an additional revenue stream.

Conclusion

In this article, I've shown

Top comments (0)