From 9837d10946d697eb3a8f07769007b50bc2ebf951 Mon Sep 17 00:00:00 2001 From: Lucas dos Santos Abreu Date: Sun, 3 Oct 2021 10:36:19 -0300 Subject: [PATCH 1/4] (feat): allow user to hide time `SHOW_TIME` will increase the size of the graph, and hide the `text` string with the amount of time. --- action.yml | 5 +++++ main.py | 26 ++++++++++++++++++++------ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/action.yml b/action.yml index 20aad13..75da132 100644 --- a/action.yml +++ b/action.yml @@ -37,6 +37,11 @@ inputs: default: "░▒▓█" required: false + SHOW_TIME: + description: "Displays the amount of time spent in each language" + default: true + required: false + runs: using: "docker" image: "Dockerfile" diff --git a/main.py b/main.py index 2a8058c..18cdc75 100644 --- a/main.py +++ b/main.py @@ -13,6 +13,7 @@ from github import Github, GithubException START_COMMENT = '' END_COMMENT = '' GRAPH_LENGTH = 25 +TEXT_LENGTH = 16 listReg = f"{START_COMMENT}[\\s\\S]+{END_COMMENT}" repository = os.getenv('INPUT_REPOSITORY') @@ -22,6 +23,7 @@ ghtoken = os.getenv('INPUT_GH_TOKEN') show_title = os.getenv("INPUT_SHOW_TITLE") commit_message = os.getenv("INPUT_COMMIT_MESSAGE") blocks = os.getenv("INPUT_BLOCKS") +show_time = os.getenv("INPUT_SHOW_TIME") def this_week() -> str: @@ -32,16 +34,16 @@ def this_week() -> str: return f"Week: {week_start.strftime('%d %B, %Y')} - {week_end.strftime('%d %B, %Y')}" -def make_graph(percent: float, blocks: str) -> str: +def make_graph(percent: float, blocks: str, length: int = GRAPH_LENGTH) -> str: '''Make progress graph from API graph''' if len(blocks) < 2: raise "The BLOCKS need to have at least two characters." divs = len(blocks) - 1 - graph = blocks[-1] * int(percent / 100 * GRAPH_LENGTH + 0.5 / divs) - remainder_block = int((percent / 100 * GRAPH_LENGTH - len(graph)) * divs + 0.5) + graph = blocks[-1] * int(percent / 100 * length + 0.5 / divs) + remainder_block = int((percent / 100 * length - len(graph)) * divs + 0.5) if remainder_block > 0: graph += blocks[remainder_block] - graph += blocks[0] * (GRAPH_LENGTH - len(graph)) + graph += blocks[0] * (length - len(graph)) return graph @@ -59,6 +61,13 @@ def get_stats() -> str: print("Please Add your WakaTime API Key to the Repository Secrets") sys.exit(1) + if show_time == 'true': + print("Will show time on graph") + ln_graph = GRAPH_LENGTH + else: + print("Hide time on graph") + ln_graph = GRAPH_LENGTH + TEXT_LENGTH + data_list = [] try: pad = len(max([l['name'] for l in lang_data[:5]], key=len)) @@ -68,12 +77,17 @@ def get_stats() -> str: for lang in lang_data[:5]: if lang['hours'] == 0 and lang['minutes'] == 0: continue + lth = len(lang['name']) - ln_text = len(lang['text']) + text = "" + if show_time == 'true': + ln_text = len(lang['text']) + text = f"{lang['text']}{' '*(TEXT_LENGTH - ln_text)}" + # following line provides a neat finish fmt_percent = format(lang['percent'], '0.2f').zfill(5) data_list.append( - f"{lang['name']}{' '*(pad + 3 - lth)}{lang['text']}{' '*(16 - ln_text)}{make_graph(lang['percent'], blocks)} {fmt_percent} % ") + f"{lang['name']}{' '*(pad + 3 - lth)}{text}{make_graph(lang['percent'], blocks, ln_graph)} {fmt_percent} % ") print("Graph Generated") data = '\n'.join(data_list) if show_title == 'true': From 271c8a29af429d8c0679d9212307901e59415e76 Mon Sep 17 00:00:00 2001 From: Lucas dos Santos Abreu Date: Wed, 6 Oct 2021 07:27:54 -0300 Subject: [PATCH 2/4] (feat): readme --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index 29acdc1..89ece82 100644 --- a/README.md +++ b/README.md @@ -205,6 +205,27 @@ Since this project is contained all within one file, `main.py`. You can simply a API_BASE_URL: https://wakapi.dev/api ``` +5. If you don't like to share how much time you spent in each language, you can add `SHOW_TIME: false` in your workflow file like this + +```yml + - uses: athul/waka-readme@master + with: + WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }} + GH_TOKEN: ${{ secrets.GH_TOKEN }} + SHOW_TIME: false +``` + +`SHOW_TIME` flag can be set to false if you don't want to display the time spent in the readme, by default it will be false. Here is an example output with `SHOW_TITLE` set to true. + +```text +Week: 11 July, 2020 - 17 July, 2020 +PHP ████████████████████▒░░░░░░░░░░░░░░░░░░░░ 49.98 % +Twig ████▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 11.07 % +YAML ████░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 09.77 % +JavaScript ██▓░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 06.34 % +Other ██▒░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░ 05.87 % +``` + ## Why only the language stats and not other data from the API? I am a fan of minimal designs and the profile readme is a great way to show off your skills and interests. The WakaTime API, gets us a **lot of data** about a person's **coding activity including the editors and Operating Systems you used and the projects you worked on**. Some of these projects maybe secretive and should not be shown out to the public. Using up more data via the Wakatime API will clutter the profile readme and hinder your chances on displaying what you provide **value to the community** like the pinned Repositories. I believe that **Coding Stats is nerdiest of all** since you can tell the community that you are _**exercising these languages or learning a new language**_, this will also show that you spend some amount of time to learn and exercise your development skills. That's what matters in the end :heart: From 6e63c24c52a7a0b6c9f73789698d58539d8f54c3 Mon Sep 17 00:00:00 2001 From: Lucas dos Santos Abreu Date: Wed, 6 Oct 2021 12:35:44 -0300 Subject: [PATCH 3/4] (fix): token is not required --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 89ece82..b1dbff9 100644 --- a/README.md +++ b/README.md @@ -211,7 +211,6 @@ Since this project is contained all within one file, `main.py`. You can simply a - uses: athul/waka-readme@master with: WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }} - GH_TOKEN: ${{ secrets.GH_TOKEN }} SHOW_TIME: false ``` From a4b0e4f26b56d519a58a42132fe09ebe87ef3cf1 Mon Sep 17 00:00:00 2001 From: Lucas dos Santos Abreu Date: Wed, 6 Oct 2021 13:45:07 -0300 Subject: [PATCH 4/4] (fix): default is true Co-authored-by: Athul Cyriac Ajay --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b1dbff9..ce582c7 100644 --- a/README.md +++ b/README.md @@ -214,7 +214,7 @@ Since this project is contained all within one file, `main.py`. You can simply a SHOW_TIME: false ``` -`SHOW_TIME` flag can be set to false if you don't want to display the time spent in the readme, by default it will be false. Here is an example output with `SHOW_TITLE` set to true. +`SHOW_TIME` flag can be set to false if you don't want to display the time spent in the readme, by default it will be true. Here is an example output with `SHOW_TIME` set to false. ```text Week: 11 July, 2020 - 17 July, 2020