Automating My Freelance Workflow with Python: A Step-by-Step Guide
As a freelance developer, I'm always looking for ways to streamline my workflow and increase productivity. One of the most effective ways I've found to do this is by automating repetitive tasks using Python. In this article, I'll walk you through the specific steps I've taken to automate my freelance workflow, including code examples and explanations.
Step 1: Setting Up a Project Management System
The first step in automating my workflow was to set up a project management system. I use a combination of Trello and GitHub to manage my projects, but I wanted to automate the process of creating new projects and assigning tasks. To do this, I used the Trello API and the requests library in Python.
import requests
# Set up Trello API credentials
trello_key = "your_trello_key"
trello_token = "your_trello_token"
# Create a new board
board_name = "New Project"
response = requests.post(
f"https://api.trello.com/1/boards/",
params={
"key": trello_key,
"token": trello_token,
"name": board_name
}
)
# Get the board ID
board_id = response.json()["id"]
# Create a new list
list_name = "To-Do"
response = requests.post(
f"https://api.trello.com/1/lists",
params={
"key": trello_key,
"token": trello_token,
"name": list_name,
"idBoard": board_id
}
)
Step 2: Automating Task Assignment
Once I had a project management system set up, I wanted to automate the process of assigning tasks. I use a combination of natural language processing (NLP) and machine learning to analyze the project requirements and assign tasks accordingly.
import spacy
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
# Load the project requirements
project_requirements = "Build a web application with a login system and user dashboard"
# Load the task templates
task_templates = [
"Build a login system",
"Build a user dashboard",
"Build a web application"
]
# Analyze the project requirements using NLP
nlp = spacy.load("en_core_web_sm")
project_requirements_doc = nlp(project_requirements)
# Calculate the similarity between the project requirements and task templates
vectorizer = TfidfVectorizer()
task_templates_vectors = vectorizer.fit_transform(task_templates)
project_requirements_vector = vectorizer.transform([project_requirements])
similarity = cosine_similarity(project_requirements_vector, task_templates_vectors)
# Assign tasks based on the similarity
tasks = []
for i, similarity_score in enumerate(similarity[0]):
if similarity_score > 0.5:
tasks.append(task_templates[i])
print(tasks)
Step 3: Automating Time Tracking
Another important aspect of freelancing is time tracking. I use a combination of the psutil library and the Toggl API to automate time tracking.
python
import psutil
import requests
# Set up Toggl API credentials
toggl_token = "your_toggl_token"
# Get the current process
current_process = psutil.Process()
# Get the current window title
window_title = current_process.cwd()
# Create a new time entry
response = requests.post(
"https://api.toggl.com/reports/v8/details",
headers={
"Authorization": f"Basic {toggl_token}",
"Content-Type": "application/json"
},
json={
"user_agent": "freelance-workflow",
"description": window_title,
"start": "2023-03-01T12:00:00Z",
"end
Top comments (0)