Last active
December 4, 2022 19:46
-
-
Save Kludex/d4a4747b82c79c90bb73b8a90494efae to your computer and use it in GitHub Desktop.
Use WakaTime API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import hashlib | |
import os | |
import httpx | |
from httpx_auth import OAuth2AuthorizationCode | |
from pydantic import BaseSettings | |
from rich.console import Console | |
console = Console() | |
class Settings(BaseSettings): | |
wakatime_client_id: str | |
wakatime_client_secret: str | |
settings = Settings() | |
auth = OAuth2AuthorizationCode( | |
authorization_url="https://wakatime.com/oauth/authorize", | |
token_url="https://wakatime.com/oauth/token", | |
client_id=settings.wakatime_client_id, | |
client_secret=settings.wakatime_client_secret, | |
redirect_uri_endpoint="oauth2callback", | |
redirect_uri_port=8000, | |
scope="email,read_stats,read_logged_time", | |
state=hashlib.sha1(os.urandom(40)).hexdigest(), | |
) | |
client = httpx.Client(base_url="https://wakatime.com/api/v1/", auth=auth) | |
res = client.get("/users/current") | |
console.print(res.json()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pydantic | |
httpx_auth @ git+https://github.com/kludex/httpx_auth.git@patch-1 | |
rich |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment