feat: allow to customize wakatime range (#874)

* chore: allow to customize wakatime data range

* docs: document wakatime range parameter
docs: add wakatime section to german readme

Co-authored-by: Anurag Hazra <hazru.anurag@gmail.com>
This commit is contained in:
Ferdinand Mütsch 2021-03-08 07:09:43 +01:00 committed by GitHub
parent 922f7165cb
commit 24e5f866c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 36 additions and 5 deletions

View File

@ -26,6 +26,7 @@ module.exports = async (req, res) => {
locale,
layout,
api_domain,
range,
border_radius,
} = req.query;
@ -36,7 +37,7 @@ module.exports = async (req, res) => {
}
try {
const stats = await fetchWakatimeStats({ username, api_domain });
const stats = await fetchWakatimeStats({ username, api_domain, range });
let cacheSeconds = clampValue(
parseInt(cache_seconds || CONSTANTS.TWO_HOURS, 10),

View File

@ -63,6 +63,7 @@
- [GitHub Statistiken-Karte](#github-statistiken-karte)
- [GitHub Extra Pins](#github-extra-pins)
- [Top Programmiersprachen-Karte](#top-programmiersprachen-karte)
- [Wakatime Wochen-Statistik](#wakatime-wochen-statistik)
- [Erscheinungsbild/Themes](#erscheinungsbildthemes)
- [Anpassungen/Personalisierung](#anpassungenpersonalisierung)
- [Selber betreiben](#betreibe-es-auf-deiner-eigenen-vercel-instanz)
@ -166,6 +167,16 @@ Du kannst mehrere, mit Kommas separierte, Werte in der bg_color Option angeben,
> Sprachennamen sollten uri-escaped sein, wie hier angegeben: [Percent Encoding](https://en.wikipedia.org/wiki/Percent-encoding)
> (z.B.: `c++` sollte zu `c%2B%2B` werden, `jupyter notebook` sollte zu `jupyter%20notebook` werden, usw.)
#### Exklusive Optionen der WakaTime-Karte:
- `hide_title` - _(boolean)_
- `line_height` - Legt die Zeilenhöhe des Texts fest _(number)_
- `hide_progress` - Verbirgt die Fortschrittanzeige und Prozentzahl _(boolean)_
- `custom_title` - Legt einen benutzerdefinierten Titel fest
- `layout` - Wechselt zwischen zwei verschiedenen Layouts: `default` & `compact`
- `api_domain` - Legt eine benutzerdefinierte API Domain fest, z.B. für [Hakatime](https://github.com/mujx/hakatime) oder [Wakapi](https://github.com/muety/wakapi)
- `range` Fragt eine eine Zeitspanne an, als die standardmäßig in WakaTime hinterlegte, z.B. `last_7_days`. Siehe [WakaTime API Dokumentation](https://wakatime.com/developers#stats).
---
# GitHub Extra Pins
@ -232,6 +243,24 @@ Du kannst die `&layout=compact` Option nutzen, um das Karten Design zu ändern.
[![Top Langs](https://github-readme-stats.vercel.app/api/top-langs/?username=anuraghazra&layout=compact)](https://github.com/anuraghazra/github-readme-stats)
# Wakatime Wochen-Statistik
Ändere `?username=` in den eigenen [Wakatime](https://wakatime.com) Benutzernamen.
```md
[![willianrod's wakatime stats](https://github-readme-stats.vercel.app/api/wakatime?username=willianrod)](https://github.com/anuraghazra/github-readme-stats)
```
### Beispiel
[![willianrod's wakatime stats](https://github-readme-stats.vercel.app/api/wakatime?username=willianrod)](https://github.com/anuraghazra/github-readme-stats)
[![willianrod's wakatime stats](https://github-readme-stats.vercel.app/api/wakatime?username=willianrod&hide_progress=true)](https://github.com/anuraghazra/github-readme-stats)
- Kompaktes Layout
[![willianrod's wakatime stats](https://github-readme-stats.vercel.app/api/wakatime?username=willianrod&layout=compact)](https://github.com/anuraghazra/github-readme-stats)
---
### Alle Beispiele

View File

@ -195,7 +195,8 @@ You can provide multiple comma-separated values in bg_color option to render a g
- `hide_progress` - Hides the progress bar and percentage _(boolean)_
- `custom_title` - Sets a custom title for the card
- `layout` - Switch between two available layouts `default` & `compact`
- `api_domain` - Set a custom api domain for the card
- `api_domain` - Set a custom API domain for the card, e.g. to use services like [Hakatime](https://github.com/mujx/hakatime) or [Wakapi](https://github.com/muety/wakapi)
- `range` Request a range different from your WakaTime default, e.g. `last_7_days`. See [WakaTime API docs](https://wakatime.com/developers#stats) for list of available options.
---

View File

@ -1,11 +1,11 @@
const axios = require("axios");
const fetchWakatimeStats = async ({ username, api_domain }) => {
const fetchWakatimeStats = async ({ username, api_domain, range }) => {
try {
const { data } = await axios.get(
`https://${
api_domain ? api_domain.replace(/[^a-z-.0-9]/gi, "") : "wakatime.com"
}/api/v1/users/${username}/stats?is_including_today=true`,
}/api/v1/users/${username}/stats/${range || ''}?is_including_today=true`,
);
return data.data;

View File

@ -105,7 +105,7 @@ describe("Wakatime fetcher", () => {
const username = "anuraghazra";
mock
.onGet(
`https://wakatime.com/api/v1/users/${username}/stats?is_including_today=true`,
`https://wakatime.com/api/v1/users/${username}/stats/?is_including_today=true`,
)
.reply(200, wakaTimeData);