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. In this article, I'll share how I use Python to automate my freelance workflow, from project management to invoicing, and how it's helped me boost my earnings.

Project Management Automation

I use Python to automate my project management workflow using the github and trello APIs. I've created a script that automatically creates a new Trello board for each new project, and adds the relevant tasks and deadlines.

import requests
import json

# GitHub API credentials
github_token = "your_github_token"
github_username = "your_github_username"

# Trello API credentials
trello_key = "your_trello_key"
trello_token = "your_trello_token"

# Create a new Trello board for each new project
def create_trello_board(project_name):
    url = f"https://api.trello.com/1/boards/"
    params = {
        "name": project_name,
        "key": trello_key,
        "token": trello_token
    }
    response = requests.post(url, params=params)
    return response.json()["id"]

# Add tasks and deadlines to the Trello board
def add_tasks(board_id, tasks):
    url = f"https://api.trello.com/1/cards"
    for task in tasks:
        params = {
            "name": task["name"],
            "desc": task["desc"],
            "idList": board_id,
            "key": trello_key,
            "token": trello_token
        }
        response = requests.post(url, params=params)

# Example usage
project_name = "New Project"
tasks = [
    {"name": "Task 1", "desc": "Task 1 description"},
    {"name": "Task 2", "desc": "Task 2 description"}
]
board_id = create_trello_board(project_name)
add_tasks(board_id, tasks)
Enter fullscreen mode Exit fullscreen mode

Time Tracking Automation

I use the time and datetime modules to track the time spent on each project. I've created a script that automatically logs the time spent on each task, and generates a report at the end of each day.

import time
import datetime

# Log time spent on each task
def log_time(task_name, start_time, end_time):
    time_spent = end_time - start_time
    with open("time_log.txt", "a") as f:
        f.write(f"{task_name}: {time_spent} minutes\n")

# Example usage
task_name = "Task 1"
start_time = time.time()
# Do some work...
end_time = time.time()
log_time(task_name, start_time, end_time)

# Generate a report at the end of each day
def generate_report():
    with open("time_log.txt", "r") as f:
        lines = f.readlines()
    report = {}
    for line in lines:
        task_name, time_spent = line.split(": ")
        if task_name in report:
            report[task_name] += int(time_spent.split(" ")[0])
        else:
            report[task_name] = int(time_spent.split(" ")[0])
    with open("report.txt", "w") as f:
        for task_name, time_spent in report.items():
            f.write(f"{task_name}: {time_spent} minutes\n")

# Example usage
generate_report()
Enter fullscreen mode Exit fullscreen mode

Invoicing Automation

I use the pdfkit library to generate invoices automatically. I've created a script that takes the time log and generates an invoice based on the time spent on each project.


python
import pdfkit
import datetime

# Generate an invoice based on the time log
def generate_invoice(time_log, project_name
Enter fullscreen mode Exit fullscreen mode

Top comments (0)