Atompub bash skript pro WP

Co takhle hodit na blog třeba výstup ze skriptu? Jelikož Wordpress podporuje publikování pomocí  protokolu Atom , tak to není vůbec problém.

Já si na to udělal jednoduchý bashový skript .



Vypada takto:

#!/bin/bash
#Author: Milos Svasek
##############################################

echo -ne "YOU MUST EDIT THIS SCRIPT AND SET ADDRESS OF YOUR BLOG.\n Than you can delete this line!" && exit

#Default values:
BASE="http://YOUR.BLOG.ADDRESS.COM/wp-app.php"
POST_CATEGORY=""
POST_TITLE=""

##############################################
# Program usage
function show_usage() {
cat< Script for remote publishing to the Wordpress blog system via Atompub
Copyright (C) 2008 Milos Svasek
This program comes with ABSOLUTELY NO WARRANTY; for details type show ${0##/} -l.

Usage: ${0##*/} [-v] -u USERNAME -p PASSWORD -t "Post title" < article.txt
or: echo "Text of article" | ${0##*/} [-v] -u USERNAME -p PASSWORD -t "Post title"
Where:
-h This help screen
-l Show license
-v Verbose mode
-q Quiet mode (no output)
-u Username (required)
-p Password (required)
-t Post title (required)
-c Post category (optional)
USAGE
}
# Program license
function show_license() {
cat<License for ${0##*/}:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see .
LICENSE
}

##############################################
# Need parameters
if ! [ $1 ] ; then
show_usage
exit
fi

# Processing parameters:
while getopts ":vqhlu:p:t:c:" optname
do
case "$optname" in
"v")
VERBOSE="-v"
;;
"q")
QUIET="TRUE"
;;
"h")
show_usage
exit
;;
"l")
show_license
exit
;;
"u")
USER="$OPTARG"
;;
"p")
PASS="$OPTARG"
;;
"t")
POST_TITLE="$OPTARG"
;;
"c")
POST_CATEGORY="$OPTARG"
;;
"?")
show_usage
echo
echo "Unknown option -$OPTARG"
exit
;;
":")
show_usage
echo
echo "No argument value for option -$OPTARG"
exit
;;
*)
show_usage
echo
echo "Unknown error while processing options"
exit
;;
esac
done

##############################################
CONTENTTYPE="Content-Type: application/atom+xml"
POST_CONTENT=`cat`
CURL="/usr/bin/curl"
##############################################

function make_xml_post() {
cat< < ?xml version="1.0" encoding="utf-8" ? >

< !\[CDATA\[$1\]\]>
< !\[CDATA\[$2\]\]>


XML_POST_METAFILE
}

if ! [ "$POST_TITLE" ] || ! [ "$POST_CONTENT" ]; then
echo "Missing data!"
exit 1
fi

# DO IT!
if [ $QUIET ];then
make_xml_post "$POST_TITLE" "$POST_CONTENT" "$POST_CATEGORY" | $CURL $VERBOSE -X POST -u $USER:$PASS --data-binary @- -H "$CONTENTTYPE" $BASE/posts &>/dev/null
else
make_xml_post "$POST_TITLE" "$POST_CONTENT" "$POST_CATEGORY" | $CURL $VERBOSE -X POST -u $USER:$PASS --data-binary @- -H "$CONTENTTYPE" $BASE/posts
fi

Žádné komentáře: