For a while I used some custom python to connect wakatime with beeminder, feel free to take whatever you like:
Wakatime wrapper:
import requests
import datetime
class WakaTime:
_key = "[your api key here]"
def get_projects(self):
date_string = datetime.datetime.now().strftime("%Y-%m-%d")
base = "https://wakatime.com/api/v1/users/current/"
endpoint = f"{base}summaries?start={date_string}&end={date_string}&api_key={self._key}"
response = requests.get(endpoint)
return response.json()['data'][0]['projects']
Sync job:
from pyminder.beeminder import Beeminder
from airtimer.croniter import Croniter
from airtimer.job import Job
from airtimer.python import Python
from airtimer.wakatime import WakaTime
class Script(Job):
# Every hour
_schedule = '0 * * * *'
_beeminder: Beeminder
_wakatime: WakaTime
def __init__(
self,
beeminder: Beeminder,
croniter: Croniter,
python: Python,
wakatime: WakaTime
):
super().__init__(croniter, python)
self._beeminder = beeminder
self._wakatime = wakatime
def run(self):
projects = self._wakatime.get_projects()
goals = self._beeminder.get_goals()
goal_names = [g['slug'] for g in goals]
filtered_projects = [p for p in projects if f"waka-{p['name']}" in goal_names]
for project in filtered_projects:
self._beeminder.create_datapoint(
f"waka-{project['name']}",
project['total_seconds'] / 60 / 60,
self._python.time_now()
)