Skip to content

Latest commit

 

History

History
279 lines (199 loc) · 12 KB

README.md

File metadata and controls

279 lines (199 loc) · 12 KB

wakatime-stats-api

The WakaTime Stats API is a tool for generating charts based on your last 7 days of coding data from Wakatime. It uses Matplotlib to make the charts and connects to the Wakatime API to get your data.

Built with Python FastAPI, it's quick and easy to use, perfect for developers who want to visualize their coding activity without much hassle.

You can customize the API to hide certain data, group items, change colors, and adjust the size of your charts. It even supports wildcards for more flexible data handling and uses GitHub language colors to color code programming languages.

Table of Contents

Showcase

API call

GET https://{domain}/api/{your_wakatime_username}/pie/languages
  ?hide=http**,**ml,docker**,json
  &width=420
  &height=215
  &vue.js=41b883
  &bash=89e051

Result

image

Features

  • API allows hiding any data you don't want to show
  • API allows defining groups of data. Useful if you don't want to show names of your work-related / confidential projects
  • API allows changing color of any data
  • API allows changing the output size of the image
  • API allows using wildcard (**) when hiding or defining groups
  • API uses GitHub languages colors for coloring languages in the /languages endpoint

Usage/Examples

Hiding all languages that start with "docker" and "java" (Dockerfile, Java, JavaScript) [case-insensitive]

GET https://{domain}/api/{your_wakatime_username}/pie/languages
  ?hide=docker**,java**

Hiding all languages that ends with "ml" (YAML, HTML) [case-insensitive]

GET https://{domain}/api/{your_wakatime_username}/pie/languages
  ?hide=**ml

Grouping work-related projects that start with "curo" and "compose-stack" specifically [case-insensitive]

GET https://{domain}/api/{your_wakatime_username}/pie/projects
  ?group=work-related
  &work-related=curo**,compose-stack

Changing colors of a group and projects individually [HEX and color names]

GET https://{domain}/api/{your_wakatime_username}/pie/projects
  ?group=work-related
  &work-related=curo**,compose-stack
  &work-related_colors=black
  &wakatime-api-stats=e5e7eb

Changing size of the output image [pixels]

GET https://{domain}/api/{your_wakatime_username}/pie/editors
  ?width=650
  &height=300

API Reference

Swagger UI is available on the /docs endpoint, but it doesn't cover all available GET parameters

Excalidraw API Spec [under the spoiler]

wakatime-api-spec

Languages

GET /api/{username}/pie/languages
Parameter Type Description
username string Required. Your WakaTime username
hide string, string [] Exact name of the language to hide.
Wildcard ** name of the language to hide with prefix** or **suffix.
Case-insensitive
Multiple value must be comma , separated
{language_name} string Key is exact name of the language case-insensitive.
Value is color in the HEX format (with or without #)
width number Width of the output image in pixels
height number Height of the output image in pixels

Editors

GET /api/{username}/pie/editors
Parameter Type Description
username string Required. Your WakaTime username
hide string, string [] Exact name of the editor to hide.
Wildcard ** name of the editor to hide with prefix** or **suffix.
Case-insensitive
Multiple value must be comma , separated
{editor_name} string Key is exact name of the editor case-insensitive.
Value is color in the HEX format (with or without #)
width number Width of the output image in pixels
height number Height of the output image in pixels

Projects

GET /api/{username}/pie/projects
Parameter Type Description
username string Required. Your WakaTime username
hide string, string [] Exact name of the project or group to hide.
Wildcard name of the project (or group) to hide with prefix** or **suffix.
Case-insensitive
Multiple value must be comma , separated
{project_name} string Key is exact name of the project case-insensitive.
Value is color in the HEX format (with or without #)
width number Width of the output image in pixels
height number Height of the output image in pixels
group string Name of the group that can be used in other parameters
{group_name} string, string [] Key is exact name of the group.
Value is exact name of the project to include in the group.
Wildcard ** name of the project to hide with prefix** or **suffix.
Case-insensitive
Multiple value must be comma , separated
{group_name}_color string Key is exact name of the group with following _color suffix.
Value is color in the HEX format (with or without #)

Local run

  1. Clone project

    git clone [email protected]:krios2146/wakatime-stats-api.git
  2. Go to project directory

    cd wakatime-stats-api
  3. Create .env file

    touch .env

    The content of the .env is the following

    WAKATIME_BASE_URL=https://wakatime.com/api/v1
    WAKATIME_API_KEY=waka_**
  4. Set up venv

    Assuming that python is installed

    python -m venv
    source venv/biv/activate
    pip install -r requirements.txt
  5. Start the API

    In dev mode with debug log configuration

    uvicorn app.main:app --reload --log-config=debug_log_config.yam

    In production mode with fast api cli

    fastapi run
  6. Alternatively, you can run it inside a Docker container

    Build

    docker build . -t wakatime-stats-api

    Run

    docker run -d -p 80:8000 --env-file .env wakatime-stats-api
  7. Call the API

    In browser type

    localhost:8000/api/{your_wakatime_username}/pie/languages
    

Deployment

To deploy this project and use it for your own purposes, you need a VPS

Deploy using GitHub package

This is the easiest way to deploy. Use the GitHub package Docker image of the project

Run on the VPS, assuming you have Docker installed:

  1. Pull the image
docker pull ghcr.io/krios2146/wakatime-stats-api:latest
  1. Don't forget to include the .env file
docker run -d -p 80:8000 --env-file .env ghcr.io/krios2146/wakatime-stats-api:latest

Deploy using Docker

The only difference with the previous variant is that you should build the Docker image from source before deployment

Run the following locally after cloning the project:

  1. Build the image
docker build . -t {docker_username}/wakatime-stats-api
  1. Push the image to your Docker repository
docker push {docker_username}/wakatime-stats-api

Run on the VPS, assuming you have Docker installed:

  1. Pull the image
docker pull {docker_username}/wakatime-stats-api
  1. Don't forget to include the .env file
docker run -d -p 80:8000 --env-file .env {docker_username}/wakatime-stats-api

Deploy without Docker

The steps are the same as in the Local run section but should be executed on the VPS