Last active
July 27, 2020 11:03
-
-
Save ivuorinen/c7af7b5dc09b619f59a4c7d67794f43f to your computer and use it in GitHub Desktop.
wp_generate_posts.sh
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
#!/usr/bin/env bash | |
# bash wp_generate_posts.sh [amount, defaults to 25] | |
# example: bash wp_generate_posts.sh 100 (to generate 100 posts) | |
_GEN_POSTS_AMOUNT_OF_POSTS=${1:-25} | |
re='^[0-9]+$' | |
if ! [[ $_GEN_POSTS_AMOUNT_OF_POSTS =~ $re ]] ; then | |
echo "error: Amount parameter must be an integer" >&2; exit 1 | |
fi | |
# Check that we have curl and wp-cli installed. | |
if ! command -v curl &> /dev/null | |
then | |
echo "curl could not be found, please install curl" | |
exit | |
fi | |
if ! command -v wp &> /dev/null | |
then | |
echo "wp could not be found, please install wp-cli" | |
exit | |
fi | |
# shellcheck disable=SC2004 | |
for ((i=0; i<$_GEN_POSTS_AMOUNT_OF_POSTS; i++)) | |
do | |
_GEN_POSTS_POST_N=$(( $i + 1 )); | |
# Random number between 100 and given amount. | |
_GEN_POSTS_RANDOM=$(( RANDOM % 100 + $_GEN_POSTS_AMOUNT_OF_POSTS )) | |
# Minus calculated random number of days and hours from now to get post date in history. | |
# Format: 2020-04-02T22:51:18 | |
_GEN_POSTS_POSTDATE=$(date +"%FT%H:%M:%S" --date="-$_GEN_POSTS_RANDOM days -$_GEN_POSTS_RANDOM hours") | |
echo "Post #$_GEN_POSTS_POST_N / $_GEN_POSTS_AMOUNT_OF_POSTS -- Date: $_GEN_POSTS_POSTDATE" | |
curl -sS -N http://loripsum.net/api/15/medium/decorate/link/ul/ol/dl/bq/code/headers | wp post generate --post_content --count=1 --post_date="$_GEN_POSTS_POSTDATE" --post_author=geniemadmin | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment