Nostr NIP-51 backups!
This commit is contained in:
commit
52448b5502
72
backup
Executable file
72
backup
Executable file
|
@ -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
|
26
kinds.json
Normal file
26
kinds.json
Normal file
|
@ -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"}
|
||||
]
|
||||
}
|
Loading…
Reference in New Issue
Block a user