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, managing multiple projects and clients can be overwhelming. To streamline my workflow and increase productivity, I turned to Python for automation. In this article, I'll share how I use Python to automate tasks, reduce manual labor, and boost my earnings.

Setting up the Environment

To start automating my workflow, I set up a Python environment on my local machine. I installed the necessary libraries, including schedule for scheduling tasks, pandas for data manipulation, and smtplib for sending emails. I also created a virtual environment using conda to ensure isolation and easy management of dependencies.

# Install required libraries
pip install schedule pandas smtplib

# Create a virtual environment
conda create --name freelance-env python=3.9
Enter fullscreen mode Exit fullscreen mode

Automating Task Management

I use a task management system to keep track of my projects and deadlines. To automate this process, I created a Python script that fetches data from my task management API and sends me reminders and notifications.

import schedule
import time
import requests
import smtplib
from email.message import EmailMessage

# Set API endpoint and credentials
api_endpoint = "https://api.example.com/tasks"
api_key = "YOUR_API_KEY"

# Set email credentials
email_username = "your_email@example.com"
email_password = "YOUR_EMAIL_PASSWORD"

# Define a function to fetch tasks and send reminders
def fetch_tasks_and_send_reminders():
    response = requests.get(api_endpoint, headers={"Authorization": f"Bearer {api_key}"})
    tasks = response.json()

    for task in tasks:
        if task["due_date"] == "today":
            # Send a reminder email
            msg = EmailMessage()
            msg.set_content(f"Reminder: {task['name']} is due today")
            msg["Subject"] = f"Reminder: {task['name']}"
            msg["From"] = email_username
            msg["To"] = email_username

            with smtplib.SMTP_SSL("smtp.example.com", 465) as smtp:
                smtp.login(email_username, email_password)
                smtp.send_message(msg)

# Schedule the function to run daily
schedule.every().day.at("08:00").do(fetch_tasks_and_send_reminders)

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

Automating Invoicing and Payment Tracking

As a freelancer, invoicing and payment tracking are crucial aspects of my workflow. To automate this process, I created a Python script that generates invoices based on my task management data and sends them to clients via email.


python
import pandas as pd
from fpdf import FPDF

# Set invoice template and client data
invoice_template = "invoice_template.pdf"
client_data = pd.read_csv("client_data.csv")

# Define a function to generate invoices
def generate_invoices():
    for index, row in client_data.iterrows():
        # Generate an invoice for each client
        pdf = FPDF()
        pdf.add_page()
        pdf.set_font("Arial", size=15)
        pdf.cell(200, 10, txt="Invoice", ln=True, align="C")

        # Add client details and invoice items
        pdf.set_font("Arial", size=10)
        pdf.cell(0, 10, txt=f"Client Name: {row['client_name']}", ln=True, align="L")
        pdf.cell(0, 10, txt=f"Project Name: {row['project_name']}", ln=True, align="L")
        pdf.cell(0, 10, txt=f"Total Amount: {row['total_amount']}", ln=True, align="L")

        # Save the invoice as a PDF
        pdf.output(f"invoice_{row['client_name']}.pdf")

        # Send the invoice
Enter fullscreen mode Exit fullscreen mode

Top comments (0)