-
-
Save appel/1f0d7a32e608a7fe29fc62ac36a9e5fe to your computer and use it in GitHub Desktop.
Import wallabag json file into a shiori instance. Reverses import order so that your newest articles remain at the top.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| help() { | |
| cat <<HELP | |
| wallbag2shiori [options] <JSON_FILE> | |
| Import wallabag json file into shiori instance. | |
| -h Print the help menu | |
| -v Enable verbose mode | |
| HELP | |
| exit; | |
| } | |
| while getopts :hv arg; do | |
| case "$arg" in | |
| h) | |
| help | |
| ;; | |
| v) | |
| set -x | |
| ;; | |
| ?) | |
| echo "ERROR: Unknown option $OPTARG" | |
| exit 2 | |
| ;; | |
| esac | |
| done | |
| # Get file path from arg | |
| shift $((OPTIND - 1)) | |
| FILE=$1 | |
| if [ -z $FILE ]; then | |
| help | |
| fi | |
| if [ ! -f $FILE ]; then | |
| echo "ERROR: Cannot find $FILE to import" | |
| exit 2 | |
| fi | |
| if [[ $FILE != *.json* ]]; then | |
| echo "ERROR: $FILE must be a json file" | |
| exit 2 | |
| fi | |
| while IFS= read -r wall; do | |
| title=$(echo $wall | jq -r '.title') | |
| url=$(echo $wall | jq -r '.url') | |
| num_tags=$(echo $wall | jq '.tags | length') | |
| if [[ $num_tags != 0 ]]; then | |
| tags=$(echo $wall | jq -r '.tags | tostring' | tr -d '\[\]' | tr -d '"') | |
| shiori add "$url" -i "$title" -t $tags | |
| else | |
| shiori add "$url" -i "$title" | |
| fi | |
| done < <(jq -c '. | reverse | .[]' < $FILE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment