Scrapbox:ページのJSONファイルを取得する
code:sbdump.sh
#!/bin/bash
WGET='/opt/homebrew/bin/wget'
ProjectName="suto3scratchpad"
cmdname=basename $0
function usage()
{
echo "Usage: ${cmdname} pageTitle" 1>&2
}
# check arguments
if $# -ne 1 ; then
usage
exit 1
fi
#echo $1
$WGET -q -O - https://scrapbox.io/api/pages/$ProjectName/$1
exit 0
# EOF
wget を使ったほうがシンプルになった
python3 はいらなくなった
code:sbdump-old.sh
#!/bin/bash
CURL='/opt/local/bin/curl'
ProjectName="suto3scratchpad"
cmdname=basename $0
function usage()
{
echo "Usage: ${cmdname} pageTitle" 1>&2
}
# check arguments
if $# -ne 1 ; then
usage
exit 1
fi
#echo $1
PageTitle=echo -n "$1" | python3 -c 'import sys, urllib.parse; print(urllib.parse.quote(sys.stdin.read()))'
#echo $PageTitle
$CURL -s https://scrapbox.io/api/pages/$ProjectName/$PageTitle
exit 0
# EOF
URLエンコーディングして、cURLでAPIを叩いているだけ。
戻ってくるのはJSON。
使い方
$ ./sbdump.sh ページ名
画面に表示(きっとわけがわからないでしょう)
$ ./sbdump.sh ページ名 | jq .
jqを使うと、すこしマシな表示になります。
$ ./sbdump.sh ページ名 > your-file.json
でファイルに保存。
$ jq . your-file.json
などで中身が確認できる。
#Scrapbox-tools
#cURL
#wget