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 earning more. In this article, I'll share how I use Python to automate my freelance workflow, from project management to invoicing.

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 project, sets up the necessary labels and milestones, and assigns the project to my client.

import requests

# GitHub API endpoint
url = "https://api.github.com/repos"

# Set your GitHub credentials
username = "your-username"
password = "your-password"

# Set the repository name and description
repo_name = "new-project"
repo_description = "This is a new project"

# Set the labels and milestones
labels = ["bug", "feature", "enhancement"]
milestones = ["v1.0", "v2.0"]

# Create a new repository
response = requests.post(url, auth=(username, password), json={
    "name": repo_name,
    "description": repo_description,
    "labels": labels,
    "milestones": milestones
})

# Check if the repository was created successfully
if response.status_code == 201:
    print("Repository created successfully")
else:
    print("Error creating repository")
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 and stops the timer based on my work schedule.

import requests
import schedule
import time

# Toggl API endpoint
url = "https://api.toggl.com/reports/v8/details"

# Set your Toggl credentials
username = "your-username"
password = "your-password"

# Set the project ID and task ID
project_id = "123456"
task_id = "abcdef"

# Start the timer
def start_timer():
    response = requests.post(url, auth=(username, password), json={
        "project_id": project_id,
        "task_id": task_id,
        "start": "now"
    })

    # Check if the timer was started successfully
    if response.status_code == 200:
        print("Timer started successfully")
    else:
        print("Error starting timer")

# Stop the timer
def stop_timer():
    response = requests.put(url, auth=(username, password), json={
        "project_id": project_id,
        "task_id": task_id,
        "stop": "now"
    })

    # Check if the timer was stopped successfully
    if response.status_code == 200:
        print("Timer stopped successfully")
    else:
        print("Error stopping timer")

# Schedule the timer to start and stop
schedule.every().day.at("09:00").do(start_timer)  # Start the timer at 9am
schedule.every().day.at("17:00").do(stop_timer)  # Stop the timer at 5pm

while True:
    schedule.run_pending()
    time.sleep(1)
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 project and sends it to my client.


python
import stripe

# Stripe API endpoint
stripe.api_key = "your-stripe-api-key"

# Set the project details
project_name = "New Project"
project_description = "This is a new project"
project_amount = 1000

# Create a new invoice
invoice = stripe.Invoice.create(
    customer="your-customer-id",
    items=[
        {
            "price_data": {
                "currency": "usd",
                "product_data": {
                    "name": project_name,
                    "description": project_description
Enter fullscreen mode Exit fullscreen mode

Top comments (0)