You've already forked wakapi-readme-stats
Initial commit
This commit is contained in:
8
Dockerfile
Normal file
8
Dockerfile
Normal file
@@ -0,0 +1,8 @@
|
||||
FROM python:latest
|
||||
|
||||
# Install dependencies.
|
||||
ADD requirements.txt /requirements.txt
|
||||
ADD main.py /main.py
|
||||
RUN pip install -r requirements.txt
|
||||
|
||||
CMD ["python", "/main.py"]
|
||||
20
LICENSE
Normal file
20
LICENSE
Normal file
@@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2020 ATHUL CYRIAC AJAY
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
13
Pipfile
Normal file
13
Pipfile
Normal file
@@ -0,0 +1,13 @@
|
||||
[[source]]
|
||||
name = "pypi"
|
||||
url = "https://pypi.org/simple"
|
||||
verify_ssl = true
|
||||
|
||||
[dev-packages]
|
||||
|
||||
[packages]
|
||||
requests = "*"
|
||||
pygithub = "*"
|
||||
|
||||
[requires]
|
||||
python_version = "3.7"
|
||||
85
Pipfile.lock
generated
Normal file
85
Pipfile.lock
generated
Normal file
@@ -0,0 +1,85 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "ee0dbc310e64a4cc599d6b5e02bb22e3f33eb97ead8e5f1e315cf355fbef9367"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
"python_version": "3.7"
|
||||
},
|
||||
"sources": [
|
||||
{
|
||||
"name": "pypi",
|
||||
"url": "https://pypi.org/simple",
|
||||
"verify_ssl": true
|
||||
}
|
||||
]
|
||||
},
|
||||
"default": {
|
||||
"certifi": {
|
||||
"hashes": [
|
||||
"sha256:5930595817496dd21bb8dc35dad090f1c2cd0adfaf21204bf6732ca5d8ee34d3",
|
||||
"sha256:8fc0819f1f30ba15bdb34cceffb9ef04d99f420f68eb75d901e9560b8749fc41"
|
||||
],
|
||||
"version": "==2020.6.20"
|
||||
},
|
||||
"chardet": {
|
||||
"hashes": [
|
||||
"sha256:84ab92ed1c4d4f16916e05906b6b75a6c0fb5db821cc65e70cbd64a3e2a5eaae",
|
||||
"sha256:fc323ffcaeaed0e0a02bf4d117757b98aed530d9ed4531e3e15460124c106691"
|
||||
],
|
||||
"version": "==3.0.4"
|
||||
},
|
||||
"deprecated": {
|
||||
"hashes": [
|
||||
"sha256:525ba66fb5f90b07169fdd48b6373c18f1ee12728ca277ca44567a367d9d7f74",
|
||||
"sha256:a766c1dccb30c5f6eb2b203f87edd1d8588847709c78589e1521d769addc8218"
|
||||
],
|
||||
"version": "==1.2.10"
|
||||
},
|
||||
"idna": {
|
||||
"hashes": [
|
||||
"sha256:b307872f855b18632ce0c21c5e45be78c0ea7ae4c15c828c20788b26921eb3f6",
|
||||
"sha256:b97d804b1e9b523befed77c48dacec60e6dcb0b5391d57af6a65a312a90648c0"
|
||||
],
|
||||
"version": "==2.10"
|
||||
},
|
||||
"pygithub": {
|
||||
"hashes": [
|
||||
"sha256:8375a058ec651cc0774244a3bc7395cf93617298735934cdd59e5bcd9a1df96e",
|
||||
"sha256:d2d17d1e3f4474e070353f201164685a95b5a92f5ee0897442504e399c7bc249"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==1.51"
|
||||
},
|
||||
"pyjwt": {
|
||||
"hashes": [
|
||||
"sha256:5c6eca3c2940464d106b99ba83b00c6add741c9becaec087fb7ccdefea71350e",
|
||||
"sha256:8d59a976fb773f3e6a39c85636357c4f0e242707394cadadd9814f5cbaa20e96"
|
||||
],
|
||||
"version": "==1.7.1"
|
||||
},
|
||||
"requests": {
|
||||
"hashes": [
|
||||
"sha256:b3559a131db72c33ee969480840fff4bb6dd111de7dd27c8ee1f820f4f00231b",
|
||||
"sha256:fe75cc94a9443b9246fc7049224f75604b113c36acb93f87b80ed42c44cbb898"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==2.24.0"
|
||||
},
|
||||
"urllib3": {
|
||||
"hashes": [
|
||||
"sha256:3018294ebefce6572a474f0604c2021e33b3fd8006ecd11d62107a5d2a963527",
|
||||
"sha256:88206b0eb87e6d677d424843ac5209e3fb9d0190d0ee169599165ec25e9d9115"
|
||||
],
|
||||
"version": "==1.25.9"
|
||||
},
|
||||
"wrapt": {
|
||||
"hashes": [
|
||||
"sha256:b62ffa81fb85f4332a4f609cab4ac40709470da05643a082ec1eb88e6d9b97d7"
|
||||
],
|
||||
"version": "==1.12.1"
|
||||
}
|
||||
},
|
||||
"develop": {}
|
||||
}
|
||||
178
README.md
Normal file
178
README.md
Normal file
@@ -0,0 +1,178 @@
|
||||
# Dev Metrics in Readme
|
||||
|
||||

|
||||
----
|
||||
|
||||
[WakaTime](https://wakatime.com) Weekly Metrics on your Profile Readme:
|
||||
|
||||
## Prep Work
|
||||
|
||||
1. You need to update the markdown file(.md) with 2 comments. You can refer [here](#update-your-readme) for updating it.
|
||||
2. You'll need a WakaTime API Key. You can get that from your WakaTime Account Settings
|
||||
- You can refer [here](#new-to-wakatime), if you're new to WakaTime
|
||||
3. **Optional** You'll need a GitHub API Token with `repo` scope from [here](https://github.com/settings/tokens) if you're running the action not in your Profile Repository
|
||||
- You can use [this](#other-repository-not-profile) example to work it out
|
||||
4. You need to save the WakaTime API Key (and the GitHub API Token, if you need it) in the repository secrets. You can find that in the Settings of your Repository.Be sure to save those as the following.
|
||||
- WakaTime-api-key as `WAKATIME_API_KEY = <your wakatime API Key>`and
|
||||
- The GitHub Access Token as `GH_TOKEN=<your github access token>`
|
||||
5. You can follow either of the Two Examples according to your needs to get started with.
|
||||
|
||||
> I strongly suggest you to run the Action in your Profile Repo since you won't be needing a GitHub Access Token
|
||||
|
||||
This Action will run everyday at 00.00 IST
|
||||
|
||||
## Update your Readme
|
||||
|
||||
Add a comment to your `README.md` like this:
|
||||
|
||||
```md
|
||||
<!--START_SECTION:waka-->
|
||||
<!--END_SECTION:waka-->
|
||||
```
|
||||
|
||||
These lines will be our entry-points for the dev metrics.
|
||||
|
||||
## New to WakaTime
|
||||
|
||||
WakaTime gives you an idea of the time you really spent on coding. This helps you boost your productivity and competitive edge.
|
||||
|
||||
- Head over to <https://wakatime.com> and create an account.
|
||||
- Get your WakaTime API Key from your [Account Settings in WakaTime](https://wakatime.com/settings/account).
|
||||
- Install the [WakaTime plugin](https://wakatime.com/plugins) in your favourite editor / IDE.
|
||||
- Paste in your API key to start the analysis.
|
||||
|
||||
### Profile Repository
|
||||
|
||||
*If you're executing the workflow on your Profile Repository (`<username>/<username>`)*
|
||||
|
||||
> You wouldn't need an GitHub Access Token since GitHub Actions already makes one for you.
|
||||
|
||||
Here is a sample workflow file for you to get started:
|
||||
|
||||
```yml
|
||||
name: Waka Readme
|
||||
|
||||
on:
|
||||
schedule:
|
||||
# Runs at 12am IST
|
||||
- cron: '30 18 * * *'
|
||||
|
||||
jobs:
|
||||
update-readme:
|
||||
name: Update this repo's README
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: anmol098/waka-readme@master
|
||||
with:
|
||||
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
|
||||
```
|
||||
|
||||
### Other Repository (not Profile)
|
||||
|
||||
*If you're executing the workflow on another repo other than `<username>/<username>`*
|
||||
|
||||
You'll need to get a [GitHub Access Token](https://docs.github.com/en/actions/configuring-and-managing-workflows/authenticating-with-the-github_token) with a `repo` scope and save it in the Repo Secrets `GH_TOKEN = <Your GitHub Access Token>`
|
||||
|
||||
Here is Sample Workflow File for running it:
|
||||
|
||||
```yml
|
||||
name: Waka Readme
|
||||
|
||||
on:
|
||||
schedule:
|
||||
# Runs at 12am IST
|
||||
- cron: '30 18 * * *'
|
||||
|
||||
jobs:
|
||||
update-readme:
|
||||
name: Update Readme with Metrics
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: anmol098/waka-readme@master
|
||||
with:
|
||||
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN }}
|
||||
USERNAME: <username> # optional, it will automatically use the username of the owner of the repository who's executing the workflow.
|
||||
```
|
||||
## Extras
|
||||
|
||||
1. If you want to add the other info to your stats, you can add multiple `FLAGS` in your workflow file by default all flags are enabled
|
||||
|
||||
```yml
|
||||
- uses: anmol098/waka-readme@master
|
||||
with:
|
||||
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
|
||||
GH_TOKEN: ${{ secrets.GH_TOKEN }}
|
||||
USERNAME: <username>
|
||||
SHOW_OS: "False"
|
||||
SHOW_PROJECTS: "False"
|
||||
```
|
||||
|
||||
#### Flags Available
|
||||
`SHOW_OS` flag can be set to `False` to hide the OS details
|
||||
|
||||
```text
|
||||
💬 Languages:
|
||||
JavaScript 5 hrs 26 mins ███████████████░░░░░░░░░░ 61.97%
|
||||
PHP 1 hr 35 mins ████░░░░░░░░░░░░░░░░░░░░░ 18.07%
|
||||
Markdown 1 hr 9 mins ███░░░░░░░░░░░░░░░░░░░░░░ 13.3%
|
||||
Python 22 mins █░░░░░░░░░░░░░░░░░░░░░░░░ 4.32%
|
||||
XML 8 mins ░░░░░░░░░░░░░░░░░░░░░░░░░ 1.62%
|
||||
|
||||
💻 Operating Systems:
|
||||
Windows 8 hrs 46 mins █████████████████████████ 100.0%
|
||||
```
|
||||
|
||||
`SHOW_PROJECTS` flag can be set to `False` to hide the Projects worked on
|
||||
|
||||
```text
|
||||
💬 Languages:
|
||||
JavaScript 5 hrs 26 mins ███████████████░░░░░░░░░░ 61.97%
|
||||
PHP 1 hr 35 mins ████░░░░░░░░░░░░░░░░░░░░░ 18.07%
|
||||
Markdown 1 hr 9 mins ███░░░░░░░░░░░░░░░░░░░░░░ 13.3%
|
||||
Python 22 mins █░░░░░░░░░░░░░░░░░░░░░░░░ 4.32%
|
||||
XML 8 mins ░░░░░░░░░░░░░░░░░░░░░░░░░ 1.62%
|
||||
|
||||
🐱💻 Projects:
|
||||
ctx_connector 4 hrs 3 mins ███████████░░░░░░░░░░░░░░ 46.33%
|
||||
NetSuite-Connector 1 hr 31 mins ████░░░░░░░░░░░░░░░░░░░░░ 17.29%
|
||||
mango-web-master 1 hr 12 mins ███░░░░░░░░░░░░░░░░░░░░░░ 13.77%
|
||||
cable 54 mins ██░░░░░░░░░░░░░░░░░░░░░░░ 10.41%
|
||||
denAPI 40 mins ██░░░░░░░░░░░░░░░░░░░░░░░ 7.66%
|
||||
|
||||
```
|
||||
|
||||
`SHOW_TIMEZONE` flag can be set to `False` to hide the time zone you are in
|
||||
|
||||
```text
|
||||
⌚︎ Timezone: Asia/Calcutta
|
||||
|
||||
💬 Languages:
|
||||
JavaScript 5 hrs 26 mins ███████████████░░░░░░░░░░ 61.97%
|
||||
PHP 1 hr 35 mins ████░░░░░░░░░░░░░░░░░░░░░ 18.07%
|
||||
Markdown 1 hr 9 mins ███░░░░░░░░░░░░░░░░░░░░░░ 13.3%
|
||||
Python 22 mins █░░░░░░░░░░░░░░░░░░░░░░░░ 4.32%
|
||||
XML 8 mins ░░░░░░░░░░░░░░░░░░░░░░░░░ 1.62%
|
||||
|
||||
```
|
||||
|
||||
`SHOW_EDITORS` flag can be set to `False` to hide the code-editor list you use
|
||||
|
||||
```text
|
||||
💬 Languages:
|
||||
JavaScript 5 hrs 26 mins ███████████████░░░░░░░░░░ 61.97%
|
||||
PHP 1 hr 35 mins ████░░░░░░░░░░░░░░░░░░░░░ 18.07%
|
||||
Markdown 1 hr 9 mins ███░░░░░░░░░░░░░░░░░░░░░░ 13.3%
|
||||
Python 22 mins █░░░░░░░░░░░░░░░░░░░░░░░░ 4.32%
|
||||
XML 8 mins ░░░░░░░░░░░░░░░░░░░░░░░░░ 1.62%
|
||||
|
||||
🔥 Editors:
|
||||
WebStorm 6 hrs 47 mins ███████████████████░░░░░░ 77.43%
|
||||
PhpStorm 1 hr 35 mins ████░░░░░░░░░░░░░░░░░░░░░ 18.07%
|
||||
PyCharm 23 mins █░░░░░░░░░░░░░░░░░░░░░░░░ 4.49%
|
||||
|
||||
```
|
||||
|
||||
This project is inspired from [athul/waka-readme](https://github.com/athul/waka-readme) with added extra feature.
|
||||
|
||||
### Don't forget to leave a ⭐ if you found this useful.
|
||||
49
action.yml
Normal file
49
action.yml
Normal file
@@ -0,0 +1,49 @@
|
||||
name: 'Waka -- Readme Stats'
|
||||
author: Anmol Pratap Singh
|
||||
description: 'Add a Wakatime Coding Activity graph in your Readme'
|
||||
|
||||
inputs:
|
||||
GH_TOKEN:
|
||||
description: 'GitHub access token with Repo scope'
|
||||
required: true
|
||||
default: ${{ github.token }}
|
||||
|
||||
WAKATIME_API_KEY:
|
||||
description: 'Your Wakatime API Key'
|
||||
required: true
|
||||
|
||||
USERNAME:
|
||||
description: 'Your GitHub username'
|
||||
required: false
|
||||
default: ${{ github.repository_owner }}
|
||||
|
||||
SHOW_OS:
|
||||
required: false
|
||||
description: 'Show the list of OS Worked on In dev metrics'
|
||||
default: "True"
|
||||
|
||||
SHOW_PROJECTS:
|
||||
required: false
|
||||
description: 'Show the list of projects worked on in dev metrics'
|
||||
default: "True"
|
||||
|
||||
SHOW_EDITORS:
|
||||
required: false
|
||||
description: 'Show the Editors used in dev metrics'
|
||||
default: "True"
|
||||
|
||||
SHOW_TIMEZONE:
|
||||
required: false
|
||||
description: 'Show the time zone in the dev metrics'
|
||||
default: "True"
|
||||
|
||||
|
||||
|
||||
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
|
||||
branding:
|
||||
icon: 'activity'
|
||||
color: 'orange'
|
||||
105
main.py
Normal file
105
main.py
Normal file
@@ -0,0 +1,105 @@
|
||||
'''
|
||||
WakaTime progress visualizer
|
||||
'''
|
||||
|
||||
import re
|
||||
import os
|
||||
import base64
|
||||
import datetime
|
||||
import pytz
|
||||
import requests
|
||||
from github import Github
|
||||
|
||||
START_COMMENT = '<!--START_SECTION:waka-->'
|
||||
END_COMMENT = '<!--END_SECTION:waka-->'
|
||||
listReg = f"{START_COMMENT}[\\s\\S]+{END_COMMENT}"
|
||||
|
||||
user = os.getenv('INPUT_USERNAME')
|
||||
waka_key = os.getenv('INPUT_WAKATIME_API_KEY')
|
||||
ghtoken = os.getenv('INPUT_GH_TOKEN')
|
||||
showTimeZone = os.getenv('INPUT_SHOW_TIMEZONE')
|
||||
showProjects = os.getenv('INPUT_SHOW_PROJECTS')
|
||||
showEditors = os.getenv('INPUT_SHOW_EDITORS')
|
||||
showOs = os.getenv('INPUT_SHOW_OS')
|
||||
|
||||
print(showTimeZone + " " + showOs + " " + showProjects + " " + showEditors)
|
||||
|
||||
|
||||
def this_week():
|
||||
'''Returns current week span'''
|
||||
week_number = datetime.date.today().isocalendar()[1]
|
||||
month = datetime.date.today().strftime('%B')
|
||||
week_start = datetime.datetime.today().day - datetime.datetime.today().weekday()
|
||||
week_end = week_start + 5
|
||||
return f"Week #{week_number} : {month} {week_start} - {week_end}"
|
||||
|
||||
|
||||
def make_graph(percent: float):
|
||||
'''Make progress graph from API graph'''
|
||||
done_block = '█'
|
||||
empty_block = '░'
|
||||
pc_rnd = round(percent)
|
||||
return f"{done_block * int(pc_rnd / 4)}{empty_block * int(25 - int(pc_rnd / 4))}"
|
||||
|
||||
|
||||
def make_list(data: list):
|
||||
'''Make List'''
|
||||
data_list = []
|
||||
for l in data[:5]:
|
||||
ln = len(l['name'])
|
||||
ln_text = len(l['text'])
|
||||
op = f"{l['name'][:25]}{' ' * (25 - ln)}{l['text']}{' ' * (20 - ln_text)}{make_graph(l['percent'])} {l['percent']}%"
|
||||
data_list.append(op)
|
||||
return ' \n'.join(data_list)
|
||||
|
||||
|
||||
def get_stats():
|
||||
'''Gets API data and returns markdown progress'''
|
||||
data = requests.get(
|
||||
f"https://wakatime.com/api/v1/users/current/stats/last_7_days?api_key={waka_key}").json()
|
||||
|
||||
stats = ''
|
||||
if showTimeZone.lower() in ['true', '1', 't', 'y', 'yes']:
|
||||
timezone = data['data']['timezone']
|
||||
stats = stats + '⌚︎ Timezone: ' + timezone + '\n\n'
|
||||
|
||||
lang_list = make_list(data['data']['languages'])
|
||||
stats = stats + '💬 Languages: \n' + lang_list + '\n\n'
|
||||
|
||||
if showEditors.lower() in ['true', '1', 't', 'y', 'yes']:
|
||||
edit_list = make_list(data['data']['editors'])
|
||||
stats = stats + '🔥 Editors: \n' + edit_list + '\n\n'
|
||||
|
||||
if showProjects.lower() in ['true', '1', 't', 'y', 'yes']:
|
||||
project_list = make_list(data['data']['projects'])
|
||||
stats = stats + '🐱💻 Projects: \n' + project_list + '\n\n'
|
||||
|
||||
if showOs.lower() in ['true', '1', 't', 'y', 'yes']:
|
||||
os_list = make_list(data['data']['operating_systems'])
|
||||
stats = stats + '💻 Operating Systems: \n' + os_list + '\n\n'
|
||||
|
||||
return '```text\n' + stats + '```'
|
||||
|
||||
|
||||
def decode_readme(data: str):
|
||||
'''Decode the contets of old readme'''
|
||||
decoded_bytes = base64.b64decode(data)
|
||||
return str(decoded_bytes, 'utf-8')
|
||||
|
||||
|
||||
def generate_new_readme(stats: str, readme: str):
|
||||
'''Generate a new Readme.md'''
|
||||
stats_in_readme = f"{START_COMMENT}\n{stats}\n{END_COMMENT}"
|
||||
return re.sub(listReg, stats_in_readme, readme)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
g = Github(ghtoken)
|
||||
repo = g.get_repo(f"{user}/{user}")
|
||||
contents = repo.get_readme()
|
||||
waka_stats = get_stats()
|
||||
rdmd = decode_readme(contents.content)
|
||||
new_readme = generate_new_readme(stats=waka_stats, readme=rdmd)
|
||||
if new_readme != rdmd:
|
||||
repo.update_file(path=contents.path, message='Updated with Dev Metrics',
|
||||
content=new_readme, sha=contents.sha, branch='master')
|
||||
10
requirements.txt
Normal file
10
requirements.txt
Normal file
@@ -0,0 +1,10 @@
|
||||
certifi==2020.6.20
|
||||
chardet==3.0.4
|
||||
Deprecated==1.2.10
|
||||
idna==2.10
|
||||
PyGithub==1.51
|
||||
PyJWT==1.7.1
|
||||
requests==2.24.0
|
||||
urllib3==1.25.9
|
||||
wrapt==1.12.1
|
||||
pytz==2020.1
|
||||
Reference in New Issue
Block a user