Last active 1747054194

script to print one post in snac, based on URL returned by search

santiago revised this gist 1747054194. Go to revision

No changes

santiago revised this gist 1747054094. Go to revision

No changes

santiago revised this gist 1747054040. Go to revision

1 file changed, 33 insertions

snacPrintPost.sh(file created)

@@ -0,0 +1,33 @@
1 + #!/usr/bin/env bash
2 +
3 + if [ -z "$1" ]; then
4 + echo "Usage: $0 <URL>"
5 + exit 1
6 + fi
7 +
8 + if [[ -z "$SNAC_BASEDIR" ]]; then
9 + echo "Error: SNAC_BASEDIR must be set." >&2
10 + exit 1
11 + fi
12 +
13 + URL="$1"
14 + ID="${URL##*/p/}"
15 + PREFIX="${ID:0:2}"
16 + FILE_PATH="$SNAC_BASEDIR/object/$PREFIX/$ID.json"
17 +
18 + if [ ! -f "$FILE_PATH" ]; then
19 + echo "Post - File not found: $FILE_PATH"
20 + exit 2
21 + fi
22 +
23 + # Extract author and content
24 + AUTHOR=$(jq -r '.attributedTo' "$FILE_PATH")
25 + CONTENT=$(jq -r '.content' "$FILE_PATH" \
26 + | sed -e 's/<[bB][rR][[:space:]]*\/?>/\n/g' \
27 + -e 's/<[^>]*>//g')
28 +
29 + # Print output
30 + echo "$CONTENT"
31 + echo
32 + echo "Author: $AUTHOR"
33 + echo "URL: $URL"
Newer Older