Merge pull request #67 from lucassabreu/feat/hide-time
(feat): option to hide time
This commit is contained in:
20
README.md
20
README.md
@@ -205,6 +205,26 @@ 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 }}
|
||||
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 true. Here is an example output with `SHOW_TIME` set to false.
|
||||
|
||||
```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:
|
||||
|
@@ -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"
|
||||
|
26
main.py
26
main.py
@@ -13,6 +13,7 @@ from github import Github, GithubException
|
||||
START_COMMENT = '<!--START_SECTION:waka-->'
|
||||
END_COMMENT = '<!--END_SECTION:waka-->'
|
||||
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':
|
||||
|
Reference in New Issue
Block a user