Automating My Freelance Workflow with Python: A Step-by-Step Guide
As a freelance developer, I've learned that automation is key to increasing productivity and reducing the time spent on mundane tasks. In this article, I'll walk you through how I use Python to automate my freelance workflow, from project management to invoicing.
Setting Up the Environment
Before we dive into the automation scripts, let's set up the environment. I recommend using a virtual environment to keep the dependencies organized. You can create a new virtual environment using the following command:
python -m venv freelance-env
Activate the virtual environment:
# On Windows
freelance-env\Scripts\activate
# On macOS/Linux
source freelance-env/bin/activate
Install the required libraries:
pip install pandas openpyxl python-dateutil
Project Management Automation
I use a simple spreadsheet to manage my projects. The spreadsheet has columns for project name, client name, deadline, and status. I'll use the pandas library to read and write data to the spreadsheet.
Create a new Python file called project_manager.py and add the following code:
import pandas as pd
from datetime import datetime
# Load the project spreadsheet
def load_projects(file_path):
try:
projects = pd.read_excel(file_path)
return projects
except FileNotFoundError:
print("File not found. Please check the file path.")
return None
# Add a new project to the spreadsheet
def add_project(file_path, project_name, client_name, deadline):
projects = load_projects(file_path)
if projects is not None:
new_project = pd.DataFrame([[project_name, client_name, deadline, "In Progress"]], columns=["Project Name", "Client Name", "Deadline", "Status"])
projects = pd.concat([projects, new_project])
projects.to_excel(file_path, index=False)
print("Project added successfully.")
# Update the status of a project
def update_project_status(file_path, project_name, status):
projects = load_projects(file_path)
if projects is not None:
projects.loc[projects["Project Name"] == project_name, "Status"] = status
projects.to_excel(file_path, index=False)
print("Project status updated successfully.")
# Example usage:
file_path = "projects.xlsx"
add_project(file_path, "New Project", "John Doe", datetime(2024, 12, 31).strftime("%Y-%m-%d"))
update_project_status(file_path, "New Project", "Completed")
Invoicing Automation
I use a template to generate invoices for my clients. The template has placeholders for the client name, project name, and amount. I'll use the openpyxl library to generate the invoice.
Create a new Python file called invoicer.py and add the following code:
import openpyxl
from openpyxl import load_workbook
# Load the invoice template
def load_template(file_path):
try:
template = load_workbook(file_path)
return template
except FileNotFoundError:
print("File not found. Please check the file path.")
return None
# Generate an invoice
def generate_invoice(file_path, client_name, project_name, amount):
template = load_template(file_path)
if template is not None:
sheet = template.active
sheet["B1"] = client_name
sheet["B2"] = project_name
sheet["B3"] = amount
template.save(f"{client_name}_{project_name}_invoice.xlsx")
print("Invoice generated successfully.")
# Example usage:
file_path = "invoice_template.xlsx"
generate_invoice(file_path, "John Doe", "New Project", 1000.0)
Monetization Angle
By
Top comments (0)