26 Commits
0.1 ... 0.1.2

Author SHA1 Message Date
Athul Cyriac Ajay
91dec6e35d Merge pull request #6 from joe733/master
feat: Added week #number to dev metrics
2020-07-17 14:02:00 +05:30
Jovial Joe Jayarson
1b5b63412c Merge branch 'master' of https://github.com/joe733/waka-readme 2020-07-17 09:07:16 +05:30
Jovial Joe Jayarson
8d201a6313 feat: Added week span and % 2020-07-17 09:06:56 +05:30
Jovial Joe Jayarson
c6628c271b feat: Added week span 2020-07-17 08:58:18 +05:30
joe733
4d999ae477 fix: one more linting :/ 2020-07-15 12:18:47 +05:30
joe733
b9ef50f20a fix: Redefining name 'stats' from outer scope ln62 2020-07-15 12:18:05 +05:30
joe733
0dc06a87bd fix & feat: added week numbers; applied linting; 2020-07-15 12:12:23 +05:30
Athul Cyriac Ajay
7563a7a8ed Update README.md 2020-07-14 01:17:24 +05:30
Athul Cyriac Ajay
b5c7fff8c3 Added Better Instructions 2020-07-14 01:04:58 +05:30
Athul Cyriac Ajay
d11a3bdb64 Merge pull request #5 from joe733/master
fix: Added WakaTime info; Some tweaks
2020-07-12 22:55:35 +05:30
Jovial Joe Jayarson
96d2a79378 fix: made requested changes. 2020-07-12 22:52:45 +05:30
Jovial Joe Jayarson
7d189fc98d fix: changed numbers to bullets; 2020-07-12 22:39:47 +05:30
Jovial Joe Jayarson
e3100077b1 Merge pull request #1 from joe733/sourcery/master
Sourcery refactored master branch
2020-07-12 22:31:26 +05:30
Jovial Joe Jayarson
79d91bc512 fix: Added WakaTime info; Some tweaks 2020-07-12 22:28:52 +05:30
Sourcery AI
4e3dc0a20a 'Refactored by Sourcery' 2020-07-12 16:25:58 +00:00
Athul Cyriac Ajay
8ac60ed14f Merge pull request #4 from gautamkrishnar/patch-1
Added screenshot for better visisbility of the workflow fearure
2020-07-12 17:20:30 +05:30
Gautam krishna R
9ea8300262 Added screenshot 2020-07-12 15:55:48 +05:30
athul
702a9a9e8e Updated Readme on Getting Wakatime API Key 2020-07-12 13:14:51 +05:30
athul
c469bfb723 Readme Updates and Usages in Profile Repo 2020-07-11 12:42:03 +05:30
Athul Cyriac Ajay
6a5ebb1ab0 Merge pull request #3 from gautamkrishnar/patch-2
Updated code to do commit only if readme changed
2020-07-11 12:02:46 +05:30
Athul Cyriac Ajay
a37900c521 Merge pull request #2 from gautamkrishnar/patch-1
Added info about USERNAME in the readme
2020-07-10 18:00:51 +05:30
Gautam krishna R
8e15ddefda Updated code to do commit only if readme changed 2020-07-10 17:33:04 +05:30
Gautam krishna R
64fb92311d Added info about USERNAME in the readme 2020-07-10 16:10:44 +05:30
athul
66fb6bbc52 Changes Token name 2020-07-10 09:49:37 +05:30
athul
30417a50d4 Minor Changes 2020-07-10 09:43:21 +05:30
Athul Cyriac Ajay
cb9b2232a8 Add Push to Master as Job 2020-07-10 09:01:48 +05:30
5 changed files with 129 additions and 68 deletions

View File

@@ -1,24 +0,0 @@
# This is a basic workflow to help you get started with Actions
name: Waka Readme
# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
schedule:
# Runs at 12am UTC
- cron: '0 0 * * *'
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Update Readme
uses: athul/waka-readme@master
with:
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}

View File

@@ -2,6 +2,7 @@ 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
CMD ["python", "/main.py"]

View File

@@ -1,30 +1,97 @@
# Dev Metrics in Readme
[Wakatime](https://wakatime.com) Weekly Metrics on your Profile Readme
![Project Preview](https://user-images.githubusercontent.com/8397274/87243943-e6b45c00-c457-11ea-94c9-2aa0bf241be8.png)
----
[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 UTC
## Update your Readme
Add a comment to your README like the follows
Add a comment to your `README.md` like this:
```md
<!--START_SECTION:waka-->
<!--END_SECTION:waka-->
```
The lines will be our entrypoints for our metrics.
These lines will be our entry-points for the dev metrics.
## How to get it
## New to WakaTime
- Clone the Repo
- Install the dependencies `pip install -r requirements.txt`
- Get a GitHub Access Token with a `repo` scope.
- Get your Wakatime API Key.
- Load env vars like
```text
GH_TOKEN = <ghtoken>
WAKATIME_API_KEY = <your wakatime API Key>
USERNAME = <github_username>
```
WakaTime gives you an idea of the time you really spent on coding. This helps you boost your productivity and competitive edge.
- Run the Script with `python main.py`
- 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 UTC
- cron: '0 0 * * *'
jobs:
update-readme:
name: Update this repo's README
runs-on: ubuntu-latest
steps:
- uses: athul/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 UTC
- cron: '0 0 * * *'
jobs:
update-readme:
name: Update Readme with Metrics
runs-on: ubuntu-latest
steps:
- uses: athul/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.
```

View File

@@ -5,6 +5,7 @@ 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:

70
main.py
View File

@@ -1,26 +1,41 @@
import base64
import requests
'''
WakaTime progress visualizer
'''
import re
import os
import base64
import datetime
import requests
from github import Github
START_COMMENT = '<!--START_SECTION:waka-->'
END_COMMENT = '<!--END_SECTION:waka-->'
listReg = f'{START_COMMENT}[\\s\\S]+{END_COMMENT}'
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")
user = os.getenv('INPUT_USERNAME')
waka_key = os.getenv('INPUT_WAKATIME_API_KEY')
ghtoken = os.getenv('INPUT_GH_TOKEN')
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 makeGraph(percent: float):
done_block = ""
empty_block = ""
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))}')
return f"{done_block*int(pc_rnd/4)}{empty_block*int(25-int(pc_rnd/4))}"
def getStats():
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()
lang_data = data['data']['languages']
@@ -28,30 +43,31 @@ def getStats():
for l in lang_data[:5]:
ln = len(l['name'])
ln_text = len(l['text'])
op = f"{l['name']}{' '*(12-ln)}{l['text']}{' '*(20-ln_text)}{makeGraph(l['percent'])} {l['percent']}"
op = f"{l['name']}{' '*(12-ln)}{l['text']}{' '*(20-ln_text)}{make_graph(l['percent'])} {l['percent']}%"
data_list.append(op)
data = " \n".join(data_list)
return ("```text\n"+data+"\n```")
data = ' \n'.join(data_list)
return '```text\n'+this_week()+'\n\n'+data+'\n```'
def decodeReadme(data: str):
decodedBytes = base64.b64decode(data)
decodedStr = str(decodedBytes, "utf-8")
return decodedStr
def decode_readme(data: str):
'''Decode the contets of old readme'''
decoded_bytes = base64.b64decode(data)
return str(decoded_bytes, 'utf-8')
def generatenewReadme(stats: str, readme: str):
statsinReadme = f"{START_COMMENT}\n{stats}\n{END_COMMENT}"
newReadme = re.sub(listReg, statsinReadme, readme)
return newReadme
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()
stats = getStats()
rdmd = decodeReadme(contents.content)
newreadme = generatenewReadme(stats=stats, readme=rdmd)
repo.update_file(path=contents.path, message="Updated with Dev Metrics",
content=newreadme, sha=contents.sha, branch="master")
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')