Fixed old code problem and add return types
This commit is contained in:
parent
15c5dbcc49
commit
610c67b096
24
README.md
24
README.md
@ -95,3 +95,27 @@ jobs:
|
||||
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 week in the Header of your stats, you can add `HEAD_FLAG: true` 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 }}
|
||||
USERNAME: <username>
|
||||
SHOW_TITLE: true
|
||||
```
|
||||
|
||||
`SHOW_TITLE` flag can be set to true if you want to display the week number and days in the readme, by default it will be false. Here is an example output with `SHOW_TITLE` set to true.
|
||||
|
||||
```text
|
||||
Week: 10 July, 2020 - 17 July, 2020
|
||||
Python 8 hrs 52 mins ███████████████████░░░░░░ 75.87 %
|
||||
Go 1 hr 15 mins ██░░░░░░░░░░░░░░░░░░░░░░░ 10.79 %
|
||||
Markdown 52 mins █░░░░░░░░░░░░░░░░░░░░░░░░ 07.43 %
|
||||
Docker 16 mins ░░░░░░░░░░░░░░░░░░░░░░░░░ 02.32 %
|
||||
YAML 7 mins ░░░░░░░░░░░░░░░░░░░░░░░░░ 01.07 %
|
||||
```
|
||||
|
@ -15,6 +15,12 @@ inputs:
|
||||
USERNAME:
|
||||
description: 'Your GitHub username'
|
||||
default: ${{ github.repository_owner }}
|
||||
required: false
|
||||
|
||||
SHOW_TITLE:
|
||||
description: "Displays the week number and days in Readme as title"
|
||||
default: false
|
||||
required: false
|
||||
|
||||
|
||||
runs:
|
||||
|
20
main.py
20
main.py
@ -17,14 +17,16 @@ 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')
|
||||
show_title = os.getenv("INPUT_SHOW_TITLE")
|
||||
|
||||
def this_week():
|
||||
def this_week() -> str:
|
||||
'''Returns a week's streak'''
|
||||
week_end = datetime.datetime.today() - datetime.timedelta(days=1)
|
||||
week_start = week_end - datetime.timedelta(days=7)
|
||||
print("Week's header Created")
|
||||
return f"Week: {week_start.strftime('%d %B, %Y')} - {week_end.strftime('%d %B, %Y')}"
|
||||
|
||||
def make_graph(percent: float):
|
||||
def make_graph(percent: float) -> str:
|
||||
'''Make progress graph from API graph'''
|
||||
done_block = '█'
|
||||
empty_block = '░'
|
||||
@ -32,7 +34,7 @@ def make_graph(percent: float):
|
||||
return f"{done_block*int(pc_rnd/4)}{empty_block*int(25-int(pc_rnd/4))}"
|
||||
|
||||
|
||||
def get_stats():
|
||||
def get_stats() -> str:
|
||||
'''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()
|
||||
@ -44,17 +46,23 @@ def get_stats():
|
||||
fmt_percent = format(l['percent'], '0.2f').zfill(5) # to provide a neat finish.
|
||||
data_list.append(
|
||||
f"{l['name']}{' '*(12-ln)}{l['text']}{' '*(20-ln_text)}{make_graph(l['percent'])} {fmt_percent} %")
|
||||
print("Graph Generated")
|
||||
data = ' \n'.join(data_list)
|
||||
return '```text\n'+this_week()+'\n\n'+data+'\n```'
|
||||
if show_title == 'false':
|
||||
print("Stats with Weeks in Title Generated")
|
||||
return '```text\n'+this_week()+'\n\n'+data+'\n```'
|
||||
else:
|
||||
print("Usual Stats Generated")
|
||||
return '```text\n'+data+'\n```'
|
||||
|
||||
|
||||
def decode_readme(data: str):
|
||||
def decode_readme(data: str) -> 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):
|
||||
def generate_new_readme(stats: str, readme: str) ->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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user