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 efficiency. By leveraging Python, I've been able to streamline my workflow, reducing the time spent on repetitive tasks and focusing on high-leverage activities. In this article, I'll share my approach to automating my freelance workflow with Python, including practical steps and code examples.

Setting up the Environment

To get started, I'll assume you have Python installed on your system. If not, you can download the latest version from the official Python website. I'll be using Python 3.9 for this example.

First, let's create a new virtual environment using venv:

python -m venv freelance-env
Enter fullscreen mode Exit fullscreen mode

Activate the virtual environment:

# On Windows
freelance-env\Scripts\activate

# On Linux/Mac
source freelance-env/bin/activate
Enter fullscreen mode Exit fullscreen mode

Now, let's install the necessary packages:

pip install requests pandas openpyxl
Enter fullscreen mode Exit fullscreen mode

Automating Client Onboarding

When a new client signs up, I need to send them a welcome email with a contract and a payment invoice. I've automated this process using Python's smtplib library.

Create a new file called client_onboarding.py and add the following code:

import smtplib
from email.mime.text import MIMEText

def send_welcome_email(client_email, client_name):
    # Define email parameters
    sender_email = "your-email@gmail.com"
    sender_password = "your-email-password"
    subject = "Welcome to our freelance services!"

    # Create email body
    body = f"Dear {client_name},\n\nWelcome to our freelance services! We're excited to have you on board.\n\nPlease find attached your contract and payment invoice.\n\nBest regards,\nYour Name"

    # Create email message
    msg = MIMEText(body)
    msg["Subject"] = subject
    msg["From"] = sender_email
    msg["To"] = client_email

    # Send email
    server = smtplib.SMTP("smtp.gmail.com", 587)
    server.starttls()
    server.login(sender_email, sender_password)
    server.sendmail(sender_email, client_email, msg.as_string())
    server.quit()

# Example usage
client_email = "client@example.com"
client_name = "John Doe"
send_welcome_email(client_email, client_name)
Enter fullscreen mode Exit fullscreen mode

Automating Time Tracking

As a freelancer, it's essential to track time spent on projects to ensure accurate invoicing. I use the pandas library to create a simple time tracking system.

Create a new file called time_tracking.py and add the following code:

import pandas as pd
from datetime import datetime

def log_time(project_name, hours_worked):
    # Load existing time log
    try:
        time_log = pd.read_csv("time_log.csv")
    except FileNotFoundError:
        time_log = pd.DataFrame(columns=["Project", "Date", "Hours Worked"])

    # Create new log entry
    new_log = pd.DataFrame({
        "Project": [project_name],
        "Date": [datetime.now().strftime("%Y-%m-%d")],
        "Hours Worked": [hours_worked]
    })

    # Append new log entry to existing log
    time_log = pd.concat([time_log, new_log])

    # Save updated time log
    time_log.to_csv("time_log.csv", index=False)

# Example usage
project_name = "Client Project"
hours_worked = 2
log_time(project_name, hours_worked)
Enter fullscreen mode Exit fullscreen mode

Automating Invoicing

With the time log in place, I can automate the invoicing process using Python's openpyxl library.

Create a new file

Top comments (0)