LoginSignup
4
4

More than 5 years have passed since last update.

様々なコマンド達を何も考えずにWP REST APIとつないで遊ぶ

Posted at

シェル芸 - 【たのしいな】様々なコマンド達を何も考えずにつないで遊ぶ - 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/

スクリーンショット_2015-12-23_23_40_28.png

新着記事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件目の記事本文を形態素解析かけるだけ。

スクリーンショット_2015-12-24_0_07_49.png

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

スクリーンショット_2015-12-24_0_00_05.png
URLと記事のIDを指定することで、松屋のメニューをコメントしていく。

スクリーンショット 2015-12-24 0.01.57.png
ただの嫌がらせである。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4