commit c3e44a45000616019efd3532f27501705fc02cf8
parent 35046f651b742d41acc97f1755f30979360449ba
Author: breadcat <breadcat@users.noreply.github.com>
Date: Tue, 29 Jul 2025 16:16:48 +0100
Additional scripts
Slowly making our way there. server.sh started at 643 lines, now is 441.
Diffstat:
3 files changed, 80 insertions(+), 0 deletions(-)
diff --git a/scripts/blog-duolingo-rank.nix b/scripts/blog-duolingo-rank.nix
@@ -0,0 +1,31 @@
+{
+ 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}')'"
+ # check
+ # write
+ echo -e "$i \e[32mdone\e[39m"
+ echo -n "Appending ranks to page... "
+ echo "| $(date +%F) | $(date +%H:%M) | $rank_streak | $rank_lingot |" | tr -d \' >>"$post_file"
+ echo -e "$i \e[32mdone\e[39m"
+ lastmod "$post_file"
+ '';
+in {
+ environment.systemPackages = [blog-duolingo-rank];
+}
diff --git a/scripts/payslips.nix b/scripts/payslips.nix
@@ -0,0 +1,28 @@
+{ pkgs, ... }:
+
+let
+ payslips = pkgs.writeShellScriptBin "payslips" ''
+ # Default destination directory, or use argument
+ destination_default="/mnt/paperwork/personal/workplace/wages"
+ destination_dir="${1:-$destination_default}"
+
+ # Process matching files
+ for file in ./*-[0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9].pdf; do
+ [[ -e "$file" ]] || continue # Skip if no match
+ filename=$(basename "$file")
+ # Extract the date
+ if [[ "$filename" =~ ([0-9]{2})-([0-9]{2})-([0-9]{4})\.pdf$ ]]; then
+ day="${BASH_REMATCH[1]}"
+ month="${BASH_REMATCH[2]}"
+ year="${BASH_REMATCH[3]}"
+ new_filename="${year}-${month}-${day}.pdf"
+ mv "$file" "$destination_dir/$new_filename"
+ echo "Moved: $file to $destination_dir/$new_filename"
+ else
+ echo "Skipped (no valid date in name): $filename"
+ fi
+ done
+ '';
+in {
+ environment.systemPackages = [ payslips ];
+}
diff --git a/scripts/tank-sort.nix b/scripts/tank-sort.nix
@@ -0,0 +1,21 @@
+{pkgs, ...}: let
+ tank-sort = pkgs.writeShellScriptBin "tank-sort" ''
+ # variables
+ temp_mount="$(mktemp -d)"
+ rclone_config="$HOME/vault/src/dockerfiles/rclone.conf"
+ rclone_remote="seedbox:"
+ destination_tvshows="/mnt/media/videos/television"
+ template_tvshows="{{ .Name }}/{{ .Name }} S{{ printf \"%02d\" .Season }}E{{ printf \"%02d\" .Episode }}{{ if ne .ExtraEpisode -1 }}-{{ printf \"%02d\" .ExtraEpisode }}{{end}}.{{ .Ext }}"
+ destination_movies="/mnt/media/videos/movies"
+ template_movies="{{ .Name }} ({{ .Year }})/{{ .Name }}.{{ .Ext }}"
+ # mount remote
+ rclone --config="$rclone_config" mount "$rclone_remote" "$temp_mount" --daemon
+ # sorting process
+ media-sort --action copy --concurrency 1 --accuracy-threshold 90 --tv-dir "$destination_tvshows" --movie-dir "$destination_movies" --tv-template "$template_tvshows" --movie-template "$template_movies" --recursive --overwrite-if-larger --extensions "mp4,m4v,mkv" "$temp_mount"
+ # unmount remote and remove
+ fusermount -uz "$temp_mount" 2>/dev/null
+ find "$temp_mount" -maxdepth 1 -mount -type d -empty -delete -print
+ '';
+in {
+ environment.systemPackages = [tank-sort];
+}