Add adc tamagotchi script. - brcon2024-hackathons - Bitreichcon 2024 Hackathons | |
git clone git://bitreich.org/brcon2024-hackathons git://enlrupgkhuxnvlhsf6lc3fz… | |
Log | |
Files | |
Refs | |
Tags | |
Submodules | |
--- | |
commit 0b190cea54fbc97803635f2bf771a2edd6b262e5 | |
parent 7ac09da5aedd5b5e3fbbdcc57adadb263f09d011 | |
Author: Christoph Lohmann <[email protected]> | |
Date: Thu, 8 Aug 2024 23:03:05 +0200 | |
Add adc tamagotchi script. | |
Diffstat: | |
A mqtt/tamagotchi-adc.sh | 31 +++++++++++++++++++++++++++++… | |
1 file changed, 31 insertions(+), 0 deletions(-) | |
--- | |
diff --git a/mqtt/tamagotchi-adc.sh b/mqtt/tamagotchi-adc.sh | |
@@ -0,0 +1,31 @@ | |
+#!/bin/sh | |
+cookiefile="$(mktemp)" | |
+datefunc() { | |
+ date +%s | |
+} | |
+datefunc >"$cookiefile" | |
+while read -r msg | |
+do | |
+ last="$(tail -n 1 "$cookiefile")" | |
+ if test "$msg" = "cookie" | |
+ then | |
+ now="$(datefunc)" | |
+ printf '%s\n' "$now" >"$cookiefile" | |
+ delta="$(printf '%s-%s\n' "$now" "$last" | bc)" | |
+ if test "$delta" -gt 28 && test "$delta" -lt 32 | |
+ then | |
+ echo ":D" | |
+ elif test "$delta" -gt 25 && test "$delta" -lt 35 | |
+ then | |
+ echo ":)" | |
+ elif test "$delta" -gt 23 && test "$delta" -lt 38 | |
+ then | |
+ echo ":|" | |
+ elif test "$delta" -gt 20 && test "$delta" -lt 40 | |
+ then | |
+ echo ":(" | |
+ else | |
+ printf 'DEAD: delta = %s s\n' "$delta" | |
+ fi | |
+ fi | |
+done |