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 freelancer, I've learned that streamlining my workflow is crucial to increasing productivity and earning more. In this article, I'll share how I use Python to automate repetitive tasks, freeing up time to focus on high-leverage activities like finding new clients and delivering quality work.

Setting up the Environment

To get started, you'll need to install Python on your machine. I recommend using the latest version of Python 3, which you can download from the official Python website. Additionally, you'll need to install the following libraries:

  • schedule for scheduling tasks
  • pyautogui for automating GUI interactions
  • pandas for data manipulation
  • openpyxl for working with Excel files

You can install these libraries using pip:

pip install schedule pyautogui pandas openpyxl
Enter fullscreen mode Exit fullscreen mode

Automating Client Onboarding

One of the most time-consuming tasks as a freelancer is onboarding new clients. This typically involves sending a welcome email, setting up a project management tool, and creating a contract. I've automated this process using Python by creating a script that sends a welcome email and sets up a new project in my project management tool.

Here's an example of how I use the smtplib library to send a welcome email:

import smtplib
from email.mime.text import MIMEText

def send_welcome_email(client_name, client_email):
    msg = MIMEText(f"Hello {client_name}, welcome to our freelance services!")
    msg['Subject'] = "Welcome to Our Freelance Services"
    msg['From'] = "your_email@example.com"
    msg['To'] = client_email

    server = smtplib.SMTP('smtp.example.com', 587)
    server.starttls()
    server.login("your_email@example.com", "your_password")
    server.sendmail("your_email@example.com", client_email, msg.as_string())
    server.quit()

send_welcome_email("John Doe", "john@example.com")
Enter fullscreen mode Exit fullscreen mode

Automating Time Tracking

As a freelancer, it's essential to track your time accurately to invoice clients correctly. I use the pyautogui library to automate time tracking by creating a script that logs my time spent on each project.

Here's an example of how I use pyautogui to log my time:

import pyautogui
import time

def log_time(project_name, hours_worked):
    pyautogui.press('win')  # opens the start menu
    pyautogui.typewrite('time tracking app')  # types the name of the time tracking app
    pyautogui.press('enter')  # opens the time tracking app
    pyautogui.typewrite(project_name)  # types the project name
    pyautogui.press('tab')  # moves to the hours worked field
    pyautogui.typewrite(str(hours_worked))  # types the hours worked
    pyautogui.press('enter')  # saves the time log

log_time("Project X", 5)
Enter fullscreen mode Exit fullscreen mode

Automating Invoice Generation

Once I've tracked my time, I need to generate an invoice for my clients. I use the openpyxl library to automate invoice generation by creating a script that populates an Excel template with my time logs and generates a PDF invoice.

Here's an example of how I use openpyxl to generate an invoice:


python
import openpyxl
from fpdf import FPDF

def generate_invoice(client_name, project_name, hours_worked):
    wb = openpyxl.load_workbook('invoice_template.xlsx')
    sheet = wb['Sheet1']

    sheet['B2'] = client_name
    sheet['B3'] = project_name
    sheet['B4'] = hours_worked
Enter fullscreen mode Exit fullscreen mode

Top comments (0)