How I Automate My Freelance Workflow with Python to Increase Productivity and Earnings
As a freelance developer, I've learned that automation is key to increasing productivity and earnings. 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 the github API to automate my project management workflow. I've created a Python script that retrieves my open projects, checks for new issues, and sends me a daily summary of my tasks.
import requests
import json
# GitHub API credentials
username = 'your_username'
token = 'your_token'
# Get open projects
def get_open_projects():
url = f'https://api.github.com/users/{username}/repos'
headers = {'Authorization': f'token {token}'}
response = requests.get(url, headers=headers)
return response.json()
# Get new issues
def get_new_issues(project):
url = f'https://api.github.com/repos/{username}/{project}/issues'
headers = {'Authorization': f'token {token}'}
response = requests.get(url, headers=headers)
return response.json()
# Send daily summary
def send_daily_summary(projects):
# Create a summary of new issues
summary = ''
for project in projects:
issues = get_new_issues(project['name'])
summary += f'**{project["name"]}**\n'
for issue in issues:
summary += f'* {issue["title"]}\n'
# Send the summary via email
import smtplib
from email.mime.text import MIMEText
msg = MIMEText(summary)
msg['Subject'] = 'Daily Project Summary'
msg['From'] = 'your_email'
msg['To'] = 'your_email'
server = smtplib.SMTP('your_smtp_server')
server.sendmail('your_email', 'your_email', msg.as_string())
server.quit()
# Main function
def main():
projects = get_open_projects()
send_daily_summary(projects)
if __name__ == '__main__':
main()
This script saves me at least an hour a day by automating my project management tasks.
Time Tracking Automation
I use the toggl API to automate my time tracking workflow. I've created a Python script that starts and stops the timer automatically based on my GitHub activity.
python
import requests
import json
import time
# Toggl API credentials
token = 'your_toggl_token'
user_agent = 'your_user_agent'
# Start timer
def start_timer(project):
url = 'https://api.toggl.com/reports/v8/details'
headers = {
'Authorization': f'Token {token}',
'User-Agent': user_agent,
'Content-Type': 'application/json'
}
data = json.dumps({
'user_agent': user_agent,
'description': project,
'tags': ['development'],
'pid': 12345 # Your project ID
})
response = requests.post(url, headers=headers, data=data)
return response.json()
# Stop timer
def stop_timer():
url = 'https://api.toggl.com/reports/v8/details'
headers = {
'Authorization': f'Token {token}',
'User-Agent': user_agent,
'Content-Type': 'application/json'
}
data = json.dumps({
'user_agent': user_agent,
'description': 'Break',
'tags': ['break'],
'pid': 12345 # Your project ID
})
response = requests.post(url, headers=headers, data=data)
return response.json()
# Main function
def main():
# Start timer when you start working on a project
project = 'My
Top comments (0)