feat: allow to configure api url (resolve #59)

This commit is contained in:
Ferdinand Mütsch 2021-04-15 22:40:56 +02:00 committed by Athul Cyriac Ajay
parent 22a8495563
commit 49db3cb845
4 changed files with 26 additions and 2 deletions

3
.gitignore vendored
View File

@ -3,3 +3,6 @@ __pycache__/
# Local VS code configurations
.vscode/
# Python virtual env
venv

View File

@ -48,6 +48,8 @@ WakaTime gives you an idea of the time you really spent on coding. This helps yo
- Install the [WakaTime plugin](https://wakatime.com/plugins) in your favourite editor / IDE.
- Paste in your API key to start the analysis.
Alternatively, you can also choose to fetch data from third-party WakaTime-compatible services like [Wakapi](https://wakapi.dev) or [Hakatime](https://github.com/mujx/hakatime) instead. For details, see [extras](#extras) section below.
### Profile Repository
_If you're executing the workflow on your Profile Repository (`<username>/<username>`)_
@ -188,6 +190,15 @@ Docker 16 mins ⣤⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀
YAML 7 mins ⣄⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀ 01.07 %
```
4. As an alternative to official WakaTime, _waka-readme_ also integrates with WakaTime-compatible services like [Wakapi](https://wakapi.dev) and [Hakatime](https://github.com/mujx/hakatime). To use one of these, adapt the API URL accordingly and use the respective service's API key instead:
```yml
- uses: athul/waka-readme@master
with:
WAKATIME_API_KEY: ${{ secrets.WAKATIME_API_KEY }}
API_BASE_URL: https://wakapi.dev/api
```
## 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:

View File

@ -12,6 +12,11 @@ inputs:
description: "Your Wakatime API Key"
required: true
API_BASE_URL:
description: "Aternative API base URL when using a third-party WakaTime backend"
default: "https://wakatime.com/api"
required: false
REPOSITORY:
description: "Your GitHub repository"
default: ${{ github.repository }}

View File

@ -17,6 +17,7 @@ listReg = f"{START_COMMENT}[\\s\\S]+{END_COMMENT}"
repository = os.getenv('INPUT_REPOSITORY')
waka_key = os.getenv('INPUT_WAKATIME_API_KEY')
api_base_url = os.getenv('INPUT_API_BASE_URL')
ghtoken = os.getenv('INPUT_GH_TOKEN')
show_title = os.getenv("INPUT_SHOW_TITLE")
commit_message = os.getenv("INPUT_COMMIT_MESSAGE")
@ -46,8 +47,12 @@ def make_graph(percent: float, blocks: str) -> str:
def get_stats() -> str:
'''Gets API data and returns markdown progress'''
encoded_key: str = str(base64.b64encode(waka_key.encode('utf-8')), 'utf-8')
data = requests.get(
f"https://wakatime.com/api/v1/users/current/stats/last_7_days?api_key={waka_key}").json()
f"{api_base_url.rstrip('/')}/v1/users/current/stats/last_7_days",
headers={
"Authorization": f"Basic {encoded_key}"
}).json()
try:
lang_data = data['data']['languages']
except KeyError: