シェル芸 - 【たのしいな】様々なコマンド達を何も考えずにつないで遊ぶ - Qiitaが面白かったので、WP REST APIを使って遊んでみました。
用意するもの
- jq
- WP REST API(Version2)が入っているWebサイト
- あの記事
cowsay
wp-cowsay.sh
#!/bin/sh
URL=${1}
if [ "${URL}" = "" ]; then
echo "Please set URL"
exit 1
fi
curl -XGET ${URL}"wp-json/wp/v2/posts" | jq ".[0].title.rendered" | cowsay
wp-cowsay.shの使い方
$ /bin/bash wp-cowsay.sh http://hoge.example.com/
新着記事1件目を牛が話す
mecab
#!/bin/sh
URL=${1}
if [ "${URL}" = "" ]; then
echo "Please set URL"
exit 1
fi
curl -XGET ${URL}"/wp-json/wp/v2/posts/" | jq ".[0].content.rendered" | mecab
こちらは真面目に新着記事1件目の記事本文を形態素解析かけるだけ。
matsuya-generator-ruby
wp-matsuya.sh
#!/bin/sh
URL=${1}
if [ "${URL}" = "" ]; then
echo "Please set URL"
exit 1
fi
ID=${2}
if [ "${ID}" = "" ]; then
echo "Please set POST ID"
exit 1
fi
COMMENT=`matsuya`
curl -XPOST ${URL}"/wp-json/wp/v2/comments/" -d "post=${ID}" -d "content=${COMMENT}"
wp-matsuya.shの使い方
$ /bin/bash wp-cowsay.sh http://hoge.example.com/ 1