Simpler implementation, utilizing GitHub's GraphQL API, and fork of:
https://github.com/berkerpeksag/github-badge
Simply update config.json
with your username and github api_key that has user repo read access and user activity. Run the generate_badge.py
script with python v3.4+, with jinja2
and requests
installed.
Then, set up a cron job or whatever you can use for a recurring / scheduled tasks to run the script periodically (something like every 24hrs) to update the generated badge.html
. Or you can setup a free jinja webapp like on pythonanywhere.com and simply check if the generated html exists or if modified date of the html file is greater than 1 day, see example script.
Remember to set permissions to deny requests all files other than the generated html file.
For GitHub Actions with GitHub Pages, see update-badge-html.yml for example usage. You will need to add a GitHub token as GH_BADGE_TOKEN
in the repository secrets. You will also need to set the GitHub Pages repository setting to use the gh-pages
branch. You will likely want to add repositories with automated commits to main/default branches in ignore_repos
in config.json
to prevent said automated commits from being considered. Otherwise, the latest commit for those repositories will nearly always be the last automated commit and not any commit by the actual user. So, the recent changes link presented in the widget will be point to potentially unwanted said commits.
You can then include the widget with the following code in similar form to:
<iframe src="https://MyWebsite.com/badge.html" style="border:0;height:128px;width:200px;overflow:hidden;" frameBorder="0"></iframe>
You can use the dark theme by specifying class="dark"
on <body>
in the html template. Or you can add ?theme=dark
to the end of the URL used for the iframe
.