How I Automate My Freelance Workflow with Python
As a freelance developer, I've learned that automating repetitive tasks is key to increasing productivity and earning more. In this article, I'll share how I use Python to streamline my workflow, from project management to invoicing.
Project Management Automation
I use the todoist API to manage my projects and tasks. With Python, I can automate task creation, assignment, and tracking. Here's an example of how I create tasks automatically:
import requests
# Todoist API credentials
api_token = "your_api_token"
project_id = 123456789
# Create a new task
task_name = "New Task"
task_description = "This is a new task"
# Set the API endpoint and headers
endpoint = f"https://api.todoist.com/rest/v1/tasks"
headers = {
"Authorization": f"Bearer {api_token}",
"Content-Type": "application/json"
}
# Set the task data
task_data = {
"project_id": project_id,
"content": task_name,
"description": task_description
}
# Send the request
response = requests.post(endpoint, headers=headers, json=task_data)
# Check if the task was created successfully
if response.status_code == 200:
print("Task created successfully")
else:
print("Error creating task")
This code creates a new task in my Todoist project using the API. I can customize the task name, description, and project ID to fit my needs.
Time Tracking Automation
I use the toggl API to track my time spent on projects. With Python, I can automate time tracking and generate reports. Here's an example of how I track time automatically:
import requests
# Toggl API credentials
api_token = "your_api_token"
workspace_id = 123456789
# Create a new time entry
project_name = "New Project"
task_name = "New Task"
start_time = "2023-03-01T09:00:00Z"
end_time = "2023-03-01T10:00:00Z"
# Set the API endpoint and headers
endpoint = f"https://api.toggl.com/reports/v8/details"
headers = {
"Authorization": f"Bearer {api_token}",
"Content-Type": "application/json"
}
# Set the time entry data
time_entry_data = {
"workspace_id": workspace_id,
"project": project_name,
"task": task_name,
"start": start_time,
"end": end_time
}
# Send the request
response = requests.post(endpoint, headers=headers, json=time_entry_data)
# Check if the time entry was created successfully
if response.status_code == 200:
print("Time entry created successfully")
else:
print("Error creating time entry")
This code creates a new time entry in my Toggl workspace using the API. I can customize the project name, task name, start time, and end time to fit my needs.
Invoicing Automation
I use the stripe API to generate invoices for my clients. With Python, I can automate invoice creation and payment tracking. Here's an example of how I create invoices automatically:
python
import stripe
# Stripe API credentials
api_key = "your_api_key"
client_id = 123456789
# Create a new invoice
invoice_items = [
{
"price_data": {
"currency": "usd",
"product_data": {
"name": "New Project"
},
"unit_amount": 1000
},
"quantity": 1
}
]
# Set the API endpoint and headers
stripe.api_key = api_key
# Create the invoice
invoice = stripe.Invoice.create(
Top comments (0)