From 52448b55021319b2ebef567705f925d2cb6b2cf7 Mon Sep 17 00:00:00 2001 From: stephen Date: Sun, 15 Sep 2024 21:18:02 -0400 Subject: [PATCH] Nostr NIP-51 backups! --- backup | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ kinds.json | 26 ++++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100755 backup create mode 100644 kinds.json diff --git a/backup b/backup new file mode 100755 index 0000000..60c0a76 --- /dev/null +++ b/backup @@ -0,0 +1,72 @@ +#!/bin/bash + +# Variables +re="" +pk="" +timestamp=$(date +%Y%m%d_%H%M%S) +base_dir="./results_$timestamp" + +# Create timestamped folder with lists and sets subfolders +mkdir -p "$base_dir/lists" "$base_dir/sets" + +# Log file for debugging +log_file="$base_dir/debug.log" +touch "$log_file" + +echo -e "How many events of each type should I try to retrieve? \r" +read nu + +# Log the user input +echo "Number of events to retrieve: $nu" | tee -a "$log_file" + +# Fetch main events and log the command +echo "Fetching main events" | tee -a "$log_file" +nak req -k 1 -l "$nu" -a "$pk" "$re" | jq > "$base_dir/main_event.json" +if [[ $? -ne 0 ]]; then + echo "Error fetching main event!" | tee -a "$log_file" +else + echo "Main event fetched successfully" | tee -a "$log_file" +fi + +# Debugging for kinds.json existence +if [[ ! -f "kinds.json" ]]; then + echo "Error: kinds.json not found!" | tee -a "$log_file" + exit 1 +fi + +# Loop through each kind in the JSON file +for item in $(jq -c '.kinds[]' kinds.json); do + # Log the current item being processed + echo "Processing item: $item" | tee -a "$log_file" + + kind=$(echo "$item" | jq -r '.kind') + description=$(echo "$item" | jq -r '.description') + category=$(echo "$item" | jq -r '.category') + + # Clean the description for filenames (remove special characters) + safe_description=$(echo "$description" | sed 's/[^a-zA-Z0-9]/_/g') + + # Determine the output directory + if [[ "$category" == "list" ]]; then + output_dir="$base_dir/lists" + elif [[ "$category" == "set" ]]; then + output_dir="$base_dir/sets" + else + echo "Skipping unknown category: $category" | tee -a "$log_file" + continue + fi + + # Fetch and save data, with logging and error handling + echo "Getting Kind $kind ($description)" | tee -a "$log_file" + nak req -k "$kind" -a "$pk" "$re" | jq > "$output_dir/${safe_description}.json" + if [[ $? -ne 0 ]]; then + echo "Error fetching Kind $kind ($description)" | tee -a "$log_file" + else + # Log the successful fetch and save + echo "Fetched and saved $output_dir/${safe_description}.json" | tee -a "$log_file" + fi +done + +# Log completion +echo "Script finished at $(date)" | tee -a "$log_file" +exit diff --git a/kinds.json b/kinds.json new file mode 100644 index 0000000..b66078e --- /dev/null +++ b/kinds.json @@ -0,0 +1,26 @@ +{ + "kinds": [ + {"kind": 10000, "description": "NIP-51_Lists_Mute_List", "category": "list"}, + {"kind": 10001, "description": "NIP-51_Lists_Pinned_Notes_List", "category": "list"}, + {"kind": 10003, "description": "NIP-51_Lists_Bookmarks_List", "category": "list"}, + {"kind": 10004, "description": "NIP-51_Lists_Communities_List", "category": "list"}, + {"kind": 10005, "description": "NIP-51_Lists_Public_Chats_List", "category": "list"}, + {"kind": 10006, "description": "NIP-51_Lists_Blocked_Relays_List", "category": "list"}, + {"kind": 10007, "description": "NIP-51_Lists_Search_Relays_List", "category": "list"}, + {"kind": 10009, "description": "NIP-51_Lists_Simple_Groups_List", "category": "list"}, + {"kind": 10015, "description": "NIP-51_Lists_Interests_List", "category": "list"}, + {"kind": 10030, "description": "NIP-51_Lists_Emoji_Sets_List", "category": "list"}, + {"kind": 10050, "description": "NIP-51_Lists_DM_Relays_List", "category": "list"}, + {"kind": 10101, "description": "NIP-51_Lists_Good_Wiki_Authors_List", "category": "list"}, + {"kind": 10102, "description": "NIP-51_Lists_Good_Wiki_Relays_List", "category": "list"}, + {"kind": 30000, "description": "NIP-51_Lists_Followed_Sets", "category": "set"}, + {"kind": 30002, "description": "NIP-51_Lists_Relay_Sets", "category": "set"}, + {"kind": 30003, "description": "NIP-51_Lists_Bookmark_Sets", "category": "set"}, + {"kind": 30004, "description": "NIP-51_Lists_Curation_Sets", "category": "set"}, + {"kind": 30005, "description": "NIP-51_Lists_Curation_Video_Sets", "category": "set"}, + {"kind": 30007, "description": "NIP-51_Lists_Mute_Sets", "category": "set"}, + {"kind": 30015, "description": "NIP-51_Lists_Interests_Sets", "category": "set"}, + {"kind": 30030, "description": "NIP-51_Lists_Emoji_Sets", "category": "set"}, + {"kind": 30063, "description": "NIP-51_Lists_Release_Artifact_Sets", "category": "set"} + ] +}