How I Automate My Freelance Workflow with Python
As a freelancer, I've learned that automation is key to increasing productivity and reducing the time spent on repetitive tasks. In this article, I'll share how I use Python to automate my freelance workflow, from project management to invoicing.
Project Management Automation
I use a combination of Python scripts and APIs to automate my project management workflow. Here's an example of how I use the Trello API to create new cards and assign tasks:
import requests
# Trello API credentials
api_key = "YOUR_API_KEY"
api_token = "YOUR_API_TOKEN"
# Create a new card
def create_card(board_id, list_id, card_name):
url = f"https://api.trello.com/1/cards"
params = {
"key": api_key,
"token": api_token,
"idList": list_id,
"name": card_name
}
response = requests.post(url, params=params)
return response.json()
# Assign a task to a card
def assign_task(card_id, member_id):
url = f"https://api.trello.com/1/cards/{card_id}/idMembers"
params = {
"key": api_key,
"token": api_token,
"value": member_id
}
response = requests.post(url, params=params)
return response.json()
# Create a new card and assign a task
board_id = "YOUR_BOARD_ID"
list_id = "YOUR_LIST_ID"
card_name = "New Card"
member_id = "YOUR_MEMBER_ID"
new_card = create_card(board_id, list_id, card_name)
assign_task(new_card["id"], member_id)
This script creates a new card on my Trello board and assigns a task to it. I can then use this script to automate the creation of new cards and tasks for each project.
Time Tracking Automation
I use the Harvest API to track my time spent on each project. Here's an example of how I use Python to automate my time tracking:
import requests
# Harvest API credentials
client_id = "YOUR_CLIENT_ID"
client_secret = "YOUR_CLIENT_SECRET"
access_token = "YOUR_ACCESS_TOKEN"
# Create a new time entry
def create_time_entry(project_id, task_id, hours):
url = "https://api.harvestapp.com/v2/time_entries"
headers = {
"Authorization": f"Bearer {access_token}",
"Content-Type": "application/json"
}
data = {
"project_id": project_id,
"task_id": task_id,
"hours": hours
}
response = requests.post(url, headers=headers, json=data)
return response.json()
# Create a new time entry
project_id = "YOUR_PROJECT_ID"
task_id = "YOUR_TASK_ID"
hours = 2
new_time_entry = create_time_entry(project_id, task_id, hours)
This script creates a new time entry on my Harvest account for the specified project and task. I can then use this script to automate my time tracking and reduce the time spent on manual entry.
Invoicing Automation
I use the Stripe API to automate my invoicing workflow. Here's an example of how I use Python to create new invoices:
python
import requests
# Stripe API credentials
api_key = "YOUR_API_KEY"
# Create a new invoice
def create_invoice(customer_id, amount):
url = "https://api.stripe.com/v1/invoices"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": "application/json"
}
data = {
"customer": customer_id,
"amount": amount
}
response = requests.post(url, headers=headers, json=data)
return response.json()
# Create a new invoice
Top comments (0)