Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: allow to customize wakatime data range #874

Merged
merged 3 commits into from
Mar 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/wakatime.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = async (req, res) => {
locale,
layout,
api_domain,
range,
border_radius,
} = req.query;

Expand All @@ -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),
Expand Down
29 changes: 29 additions & 0 deletions docs/readme_de.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---

Expand Down
4 changes: 2 additions & 2 deletions src/fetchers/wakatime-fetcher.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 1 addition & 1 deletion tests/fetchWakatime.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down