Last active
March 5, 2020 21:11
-
-
Save airtonzanon/4fcb8c9d9240458e8d23ae89c55b10ad to your computer and use it in GitHub Desktop.
Get your wakatime spend on languages and create an ascii chart.
This file contains 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 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 |
This file contains 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
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