commit d980e43eecf8c9aa0c62c7eb42ad2fd5f0d32b36
parent 7cbcd7a5324c80e75229822970973c251e781f85
Author: breadcat <breadcat@users.noreply.github.com>
Date: Tue, 5 Aug 2025 17:31:17 +0100
Merge blog-duo and cron, move to artemis
Only on ilias for testing purposes
Diffstat:
5 files changed, 46 insertions(+), 51 deletions(-)
diff --git a/common/blog-duolingo.nix b/common/blog-duolingo.nix
@@ -0,0 +1,45 @@
+{ pkgs, username, domain, ... }:
+
+let
+ blog-duolingo = pkgs.writeShellScriptBin "blog-duolingo" ''
+ # variables
+ username="$(awk -F'[/()]' '/Duolingo/ {print $5}' "$HOME/vault/src/blog.${domain}/content/about.md")"
+ post_file="$HOME/vault/src/blog.${domain}/content/posts/logging-duolingo-ranks-over-time.md"
+ # functions
+ function lastmod {
+ echo -n "Amending lastmod value... "
+ mod_timestamp="$(date +%FT%H:%M:00)"
+ sed -i "s/lastmod: .*/lastmod: $mod_timestamp/g" "$1"
+ echo -e "$i \e[32mdone\e[39m"
+ }
+ # process
+ page_source="$(curl -s https://duome.eu/"$username")"
+ rank_lingot="$(printf %s "$page_source" | awk -F"[#><]" '/icon lingot/ {print $15}')"
+ rank_streak="$(printf %s "$page_source" | awk -F"[#><]" '/icon streak/{getline;print $15}')"
+ # write
+ echo -e "$i \e[32mdone\e[39m"
+ echo -n "Appending ranks to page... "
+ sed -i '/<\/tbody><\/table>/d' "$post_file"
+ printf " <tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n</tbody></table>" "$(date +%F)" "$(date +%H:%M)" "$rank_streak" "$rank_lingot" >>"$post_file"
+ echo -e "$i \e[32mdone\e[39m"
+ lastmod "$post_file"
+ '';
+in {
+ environment.systemPackages = [blog-duolingo];
+
+ systemd.timers.blog-duolingo = {
+ wantedBy = [ "timers.target" ];
+ timerConfig = {
+ OnCalendar = "Sun 23:59";
+ Persistent = true;
+ };
+ };
+ systemd.services.blog-duolingo = {
+ script = "blog-duolingo";
+ path = [ "/run/current-system/sw" ];
+ serviceConfig = {
+ Type = "oneshot";
+ User = "${username}";
+ };
+ };
+}
diff --git a/common/cron-duolingo-rank.nix b/common/cron-duolingo-rank.nix
@@ -1,18 +0,0 @@
-{ username, ... }:
-{
- systemd.timers.duolingo-rank = {
- wantedBy = [ "timers.target" ];
- timerConfig = {
- OnCalendar = "Sun 23:59";
- Persistent = true;
- };
- };
- systemd.services.duolingo-rank = {
- script = "blog-duolingo-rank";
- path = [ "/run/current-system/sw" ];
- serviceConfig = {
- Type = "oneshot";
- User = "${username}";
- };
- };
-}
diff --git a/machines/artemis.nix b/machines/artemis.nix
@@ -24,6 +24,7 @@ in {
./${machine}-hardware.nix # Include the results of the hardware scan.
(import "${home-manager}/nixos") # Home-Manager
(import ../common/docker.nix {inherit config pkgs username domain timezone todosecret vpnusername vpnpassword;})
+ (import ../common/blog-duolingo.nix {inherit pkgs domain username;})
../common/flakes.nix
../common/garbage.nix
(import ../common/locale.nix {inherit pkgs timezone;})
diff --git a/machines/ilias.nix b/machines/ilias.nix
@@ -20,7 +20,6 @@ in {
imports = [
./${machine}-hardware.nix # Include the results of the hardware scan.
(import "${home-manager}/nixos") # Home-Manager
- (import ../common/cron-duolingo-rank.nix {inherit username;})
../common/flakes.nix
../common/garbage.nix
(import ../common/locale.nix {inherit pkgs timezone;})
@@ -35,7 +34,6 @@ in {
(import ../common/user.nix {inherit config pkgs username fullname;})
(import ../scripts/audiobook-cleaner.nix {inherit pkgs domain;})
../scripts/backup-local.nix
- (import ../scripts/blog-duolingo-rank.nix {inherit pkgs domain;})
(import ../scripts/blog-music.nix {inherit pkgs domain;})
(import ../scripts/blog-sort-archives.nix {inherit pkgs domain;})
(import ../scripts/blog-sort-languages.nix {inherit pkgs domain;})
diff --git a/scripts/blog-duolingo-rank.nix b/scripts/blog-duolingo-rank.nix
@@ -1,31 +0,0 @@
-{
- pkgs,
- domain,
- ...
-}: let
- blog-duolingo-rank = pkgs.writeShellScriptBin "blog-duolingo-rank" ''
- # variables
- username="$(awk -F'[/()]' '/Duolingo/ {print $5}' "$HOME/vault/src/blog.${domain}/content/about.md")"
- post_file="$HOME/vault/src/blog.${domain}/content/posts/logging-duolingo-ranks-over-time.md"
- # functions
- function lastmod {
- echo -n "Amending lastmod value... "
- mod_timestamp="$(date +%FT%H:%M:00)"
- sed -i "s/lastmod: .*/lastmod: $mod_timestamp/g" "$1"
- echo -e "$i \e[32mdone\e[39m"
- }
- # process
- page_source="$(curl -s https://duome.eu/"$username")"
- rank_lingot="$(printf %s "$page_source" | awk -F"[#><]" '/icon lingot/ {print $15}')"
- rank_streak="$(printf %s "$page_source" | awk -F"[#><]" '/icon streak/{getline;print $15}')"
- # write
- echo -e "$i \e[32mdone\e[39m"
- echo -n "Appending ranks to page... "
- sed -i '/<\/tbody><\/table>/d' "$post_file"
- printf " <tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n</tbody></table>" "$(date +%F)" "$(date +%H:%M)" "$rank_streak" "$rank_lingot" >>"$post_file"
- echo -e "$i \e[32mdone\e[39m"
- lastmod "$post_file"
- '';
-in {
- environment.systemPackages = [blog-duolingo-rank];
-}