mirror of
https://github.com/jooray/nostr-scripts.git
synced 2026-06-02 07:02:07 +00:00
initial commit
This commit is contained in:
commit
140790db60
26
LICENSE
Normal file
26
LICENSE
Normal file
@ -0,0 +1,26 @@
|
||||
GLWTS(Good Luck With That Shit) Public License
|
||||
Copyright (c) Every-fucking-one, except the Author
|
||||
|
||||
Everyone is permitted to copy, distribute, modify, merge, sell, publish,
|
||||
sublicense or whatever the fuck they want with this software but at their
|
||||
OWN RISK.
|
||||
|
||||
Preamble
|
||||
|
||||
The author has absolutely no fucking clue what the code in this project
|
||||
does. It might just fucking work or not, there is no third option.
|
||||
|
||||
|
||||
GOOD LUCK WITH THAT SHIT PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION, AND MODIFICATION
|
||||
|
||||
0. You just DO WHATEVER THE FUCK YOU WANT TO as long as you NEVER LEAVE
|
||||
A FUCKING TRACE TO TRACK THE AUTHOR of the original product to blame for
|
||||
or hold responsible.
|
||||
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
|
||||
Good luck and Godspeed.
|
||||
21
README.md
Normal file
21
README.md
Normal file
@ -0,0 +1,21 @@
|
||||
# nostr-scripts
|
||||
|
||||
These are a few scripts that I use for Nostr.
|
||||
|
||||
They usually need [nak](https://github.com/fiatjaf/nak) in PATH.
|
||||
|
||||
## nostr-backup.sh
|
||||
|
||||
Used to backup my notes to my own relay. You need to edit the script to configure everything,
|
||||
it's well commented.
|
||||
|
||||
I run it from cron.
|
||||
|
||||
## slow-post.py
|
||||
|
||||
Used to slowly post events to a nostr relay. Many relays have rate limits, so I want to delay
|
||||
posting, so I don't hammer them with events. You can adjust the speed of posting by changing the sleep time in the source code.
|
||||
|
||||
## slow-post-all.sh
|
||||
|
||||
Micro script that orchestrates posting to many relays at once. Uses slow-post.py.
|
||||
45
nostr-backup.sh
Normal file
45
nostr-backup.sh
Normal file
@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Gets the events authored by users mentioned in the for cycle
|
||||
# and publishes them to a target relay
|
||||
|
||||
# Use when you deploy your own relay and want to use it as a backup
|
||||
# for your events
|
||||
|
||||
# See comments for what and how to adjust
|
||||
|
||||
# Where to publish it to (f.e. your own relay)
|
||||
TARGET_RELAY="wss://nostr.my.relay"
|
||||
# Since when to start getting events. If you run this from cron, can be
|
||||
# for example 7 days ago.
|
||||
SINCE=$(date -d "7 days ago" +%s)
|
||||
# For first run:
|
||||
# SINCE=0
|
||||
|
||||
# Make sure ~/tmp exists, or else it will fail
|
||||
> ~/tmp/nostr-backup.json
|
||||
|
||||
# hex of the nostr account you want to backup (get hex from npub
|
||||
# at https://nostrcheck.me/converter/ )
|
||||
# You can add as many as you want, add \ to the end of each but the last line
|
||||
|
||||
for author in \
|
||||
"dab6c6065c439b9bafb0b0f1ff5a0c68273bce5c1959a4158ad6a70851f507b6"
|
||||
do
|
||||
echo "Getting notes for author ${author}..."
|
||||
# Here is the set of source relays (where we want to get events from)
|
||||
for relay in \
|
||||
"wss://nostr.mom" \
|
||||
'wss://nos.lol' \
|
||||
'wss://nostr.bitcoiner.social' \
|
||||
'wss://relay.nostr.band' \
|
||||
'wss://relay.damus.io' \
|
||||
'wss://relay.nostrplebs.com'
|
||||
do
|
||||
echo " --> from relay ${relay}..."
|
||||
nak req --author "${author}" --since "${SINCE}" "${relay}" >> ~/tmp/nostr-backup.json
|
||||
done
|
||||
done
|
||||
|
||||
echo "Publishing to ${TARGET_RELAY}..."
|
||||
sort -u ~/tmp/nostr-backup.json | nak event ${TARGET_RELAY}
|
||||
11
slow-post-all.sh
Normal file
11
slow-post-all.sh
Normal file
@ -0,0 +1,11 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Take a file as argument and publish it to relays mentioned in the for cycle below
|
||||
# File should be a jsonl file with one json object per line
|
||||
|
||||
for RELAY in wss://relay.nostrplebs.com wss://relay.nostr.band
|
||||
do
|
||||
echo "Publishing to ${RELAY}"
|
||||
# We can post to different relays in parallel, they don't know about each other
|
||||
do python3 slow-post.py "${RELAY}" < "${1}";done ) &
|
||||
done
|
||||
26
slow-post.py
Normal file
26
slow-post.py
Normal file
@ -0,0 +1,26 @@
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
|
||||
if len(sys.argv) < 2:
|
||||
print("Error: Not enough arguments provided, I need a relay.")
|
||||
sys.exit(1)
|
||||
|
||||
relay = sys.argv[1]
|
||||
|
||||
data = json.loads(sys.stdin.read())
|
||||
|
||||
# Execute the binary for each element in the JSON array
|
||||
for item in data:
|
||||
# Replace 'binary_path' with the actual path to your binary executable
|
||||
process = subprocess.Popen(['nak','event', relay], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
process.stdin.write(json.dumps(item).encode('utf-8')) # Send the item as a JSON string to the process's stdin
|
||||
process.stdin.flush()
|
||||
output, error = process.communicate()
|
||||
|
||||
# Print the output and error (if any) for debugging purposes
|
||||
print('Output:', output.decode('utf-8'))
|
||||
print('Error:', error.decode('utf-8'))
|
||||
|
||||
time.sleep(1)
|
||||
Loading…
x
Reference in New Issue
Block a user