Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get your wakatime spend on languages and create an ascii chart.
import requests, json, os
# To get the WAKATIME_JSON_URL_PER_LANGUAGE
# Go to https://wakatime.com/share/embed, choose JSON format, choose languages chart type
# Click on "Get Embeddable Code", copy the url that it'll show
resp = requests.get(os.environ.get('WAKATIME_URL'))
data = []
for wakadata in resp.json()["data"]:
data.append((wakadata["name"], wakadata["percent"]))
# Thanks to @alexwlchan for this post:
# https://alexwlchan.net/2018/05/ascii-bar-charts/
# This code is exactly as yours.
max_value = max(count for _, count in data)
increment = max_value / 25
longest_label_length = max(len(label) for label, _ in data)
output = ""
for label, count in data:
round(count, 2)
bar_chunks, remainder = divmod(int(count * 8 / increment), 8)
bar = chr(9619) * bar_chunks
if remainder > 0:
bar += chr(9619)
bar = bar or ""
output += f'{label.rjust(longest_label_length)} - {count:#5.2f}% {bar} \n'
# You can find this here:
# https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line
github_token = os.environ.get('GITHUB_TOKEN')
gist_id = os.environ.get('GIST_ID') # the one on your gist URL
# You need to create (or change the name below) a file called weekly_development_breakdown.txt on your gist
data = {
"files": {
"weekly_development_breakdown.txt": {
"content": output,
"filename": "weekly_development_breakdown.txt"
}
}
}
headers = {"Authorization": "token " + github_token}
gist = requests.patch("https://api.github.com/gists/" + gist_id, data=json.dumps(data), headers=headers)
print(gist.json())
# Inspired by @malukenho that created this gist:
# https://gist.github.com/malukenho/4af1e0bbba4f0a379e8f47f771a6ca1f
SQL - 92.20% ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓
YAML - 5.24% ▓▓
PHP - 2.28% ▓
Other - 0.24%
JavaScript - 0.04%
JSON - 0.00%
Markdown - 0.00%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment