How I Automate My Freelance Workflow with Python
As a freelance developer, I've learned that automation is key to increasing productivity and earning more. In this article, I'll share how I use Python to automate my workflow, from project management to invoicing, and how it's helped me boost my income.
Project Management Automation
I use the github library in Python to automate my project management workflow. I've created a script that automatically creates a new GitHub repository for each new project, sets up the basic structure, and invites my clients to the repository. Here's an example of how I do it:
import github
# GitHub API credentials
GITHUB_TOKEN = 'your-github-token'
GITHUB_USERNAME = 'your-github-username'
# Create a new GitHub repository
def create_repository(project_name):
g = github.Github(GITHUB_TOKEN)
user = g.get_user(GITHUB_USERNAME)
repo = user.create_repo(project_name)
return repo
# Set up basic repository structure
def setup_repository(repo):
# Create a new branch for development
repo.create_git_ref(ref='refs/heads/development', sha=repo.get_branch('main').commit.sha)
# Create a new issue for the project
repo.create_issue(title='Project Description', body='This is a new project')
# Invite client to the repository
def invite_client(repo, client_username):
repo.add_to_collaborators(client_username, permission='push')
# Example usage
project_name = 'new-project'
client_username = 'client-username'
repo = create_repository(project_name)
setup_repository(repo)
invite_client(repo, client_username)
This script saves me a significant amount of time and ensures that all my projects follow the same structure.
Time Tracking Automation
I use the toggl library in Python to automate my time tracking workflow. I've created a script that automatically starts a new Toggl timer for each new task, and stops the timer when the task is completed. Here's an example of how I do it:
import toggl
# Toggl API credentials
TOGGL_TOKEN = 'your-toggl-token'
TOGGL_WORKSPACE = 'your-toggl-workspace'
# Create a new Toggl timer
def start_timer(project_name, task_name):
t = toggl.Toggl(TOGGL_TOKEN)
project = t.get_project(TOGGL_WORKSPACE, project_name)
task = t.create_task(project['id'], task_name)
t.start_timer(task['id'])
# Stop the Toggl timer
def stop_timer(task_id):
t = toggl.Toggl(TOGGL_TOKEN)
t.stop_timer(task_id)
# Example usage
project_name = 'new-project'
task_name = 'new-task'
start_timer(project_name, task_name)
# ... do some work ...
stop_timer(t.get_running_time_entry()['id'])
This script ensures that I accurately track all the time I spend on each project, which helps me bill my clients more accurately.
Invoicing Automation
I use the stripe library in Python to automate my invoicing workflow. I've created a script that automatically generates an invoice for each client at the end of each month, and sends it to them via email. Here's an example of how I do it:
python
import stripe
# Stripe API credentials
STRIPE_TOKEN = 'your-stripe-token'
# Create a new Stripe invoice
def create_invoice(client_email, amount):
stripe.api_key = STRIPE_TOKEN
invoice = stripe.Invoice.create(
customer=client_email,
amount=amount,
currency='usd'
)
return invoice
# Send the invoice to the client
def send_invoice(invoice):
# Send the invoice via email
# ... implementation ...
Top comments (0)