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 streamline my workflow, from project management to invoicing.

Project Management Automation

I use the schedule library to automate repetitive tasks, such as sending reminders to clients and updating project status. Here's an example of how I use it:

import schedule
import time
from datetime import datetime

def send_reminder(client_email, project_name):
    # Send email using SMTP
    print(f"Sending reminder to {client_email} for {project_name}")

def update_project_status(project_name, status):
    # Update project status in database
    print(f"Updating {project_name} status to {status}")

# Schedule tasks
schedule.every().day.at("08:00").do(send_reminder, "client@example.com", "Project X")
schedule.every().day.at("17:00").do(update_project_status, "Project X", "In Progress")

while True:
    schedule.run_pending()
    time.sleep(1)
Enter fullscreen mode Exit fullscreen mode

This code sends a reminder to the client every morning at 8am and updates the project status every evening at 5pm.

Time Tracking Automation

I use the psutil library to track the time spent on each project. Here's an example of how I use it:

import psutil
import time
from datetime import datetime

def track_time(project_name):
    start_time = datetime.now()
    while True:
        # Get current process
        process = psutil.Process()
        # Get current CPU usage
        cpu_usage = process.cpu_percent()
        # Get current memory usage
        memory_usage = process.memory_percent()
        print(f"Project: {project_name}, CPU: {cpu_usage}%, Memory: {memory_usage}%")
        time.sleep(1)

# Start tracking time
track_time("Project X")
Enter fullscreen mode Exit fullscreen mode

This code tracks the CPU and memory usage of the current process and prints the project name, CPU usage, and memory usage every second.

Invoicing Automation

I use the pdfkit library to generate invoices automatically. Here's an example of how I use it:

import pdfkit
from datetime import datetime

def generate_invoice(client_name, project_name, amount):
    # Generate invoice HTML
    html = f"""
    <html>
    <body>
    <h1>Invoice for {client_name}</h1>
    <p>Project: {project_name}</p>
    <p>Amount: ${amount}</p>
    <p>Date: {datetime.now().strftime("%Y-%m-%d")}</p>
    </body>
    </html>
    """
    # Generate PDF
    pdfkit.from_string(html, "invoice.pdf")

# Generate invoice
generate_invoice("Client X", "Project X", 1000)
Enter fullscreen mode Exit fullscreen mode

This code generates an invoice HTML and converts it to a PDF using pdfkit.

Monetization Angle

By automating my freelance workflow, I've been able to increase my productivity and take on more projects. This has resulted in a significant increase in my earnings. I've also been able to offer more services to my clients, such as project management and time tracking, which has helped me to differentiate myself from other freelancers.

Putting it all Together

To put all of these automation tools together, I use a combination of Python scripts and scheduling tools like schedule and apscheduler. I also use a database to store project information and client data.

Here's an example of how I use apscheduler to schedule tasks:


python
from apscheduler.schedulers.blocking import BlockingScheduler

def send_reminder(client_email, project_name):
    # Send email using SMTP
    print(f"Sending
Enter fullscreen mode Exit fullscreen mode

Top comments (0)