Browse Source

Initial commit

ApisNecros 1 year ago
commit
f1edc27d8f
2 changed files with 62 additions and 0 deletions
  1. 35 0
      deadtrunkswitch.py
  2. 27 0
      original.sh

+ 35 - 0
deadtrunkswitch.py

@@ -0,0 +1,35 @@
+import sqlite3
+import argparse
+
+def load_config():
+    pass;
+
+def load_message_templates():
+    pass
+
+def check_heartbeat():
+    pass
+
+def update_heartbeat():
+    print("Ba-duh")
+
+def initialize_sqlite():
+    print("Initializing...")
+
+if __name__ == "__main__":
+    # Initialize the CLI arguments
+    parser = argparse.ArgumentParser(
+        prog="DeadTrunkSwitch", 
+        description="A Mastodon-based deadman's switch",
+        formatter_class=argparse.ArgumentDefaultsHelpFormatter
+    )
+    parser.add_argument("-d", "--database", default="./db.sqlite", help="The SQLite file to track the switch with")
+    action_group = parser.add_mutually_exclusive_group()
+    action_group.add_argument("--checkIn", action="store_true", help="Update the last check-in time")
+    action_group.add_argument("--init", action="store_true", help="Initialize the database for the deadman's switch")
+    args = parser.parse_args()
+    # Begin option handling
+    if args.init:
+        initialize_sqlite()
+    elif args.checkIn:
+        update_heartbeat()

+ 27 - 0
original.sh

@@ -0,0 +1,27 @@
+#!/bin/bash
+
+file_path="$HOME/.scripts/buskill"
+
+failed_path="$file_path/.failed"
+countdown_path="$file_path/countdown.template"
+last_status_path="$file_path/.last_status"
+
+days_missed=$(<"$failed_path")
+
+if [ "$days_missed" = "" ]; then
+        days_missed=0
+fi
+
+echo "Days Missed: $days_missed"
+
+if [ "$days_missed" -gt 0 ]; then
+    status_content="$(sed "s/%days%/$days_missed/" < "$countdown_path")"
+    toot_output="$(toot post "$status_content")"
+    status_id="$(echo "$toot_output" | awk -F '/' '{print $6}')"
+    let days_missed++
+    echo "$days_missed" > "$failed_path"
+    echo "$status_id" > "$last_status_path"
+else
+   echo 1 > "$failed_path"
+   echo > "$last_status_path"
+fi