Journal James A. A. Joyce's Journal: Comment posting POST data
I'm just documenting some of my thought processes regarding noninteractive comment posting, which may help me to build an automated post poster out of bash.
When posting a comment AC (which is what my planned script will do for convenience's sake) one first has to preview the comment and then submit it: they're both exactly the same operations except that for one the POST variable "op" is set to "Preview" and for the other it's "Submit". So we can just post the same variables twice.
Except...there's the formkeys. We have to generate formkeys somehow. Actually, that's quite simple. We just simulate the clicking of a Reply link and we get a valid comment submit form with a valid formkey. We fill it in, hit Preview, then get a new form with another formkey. Use that, fill it in, submit, done.
Oh, and then, there's the waiting for a smidge under 20 seconds for the lameness filter.
OK, the rest of this journal entry is going to be another experimental bash shell script:
---------
#!/bin/bash
show_usage=0
if echo "$1" | egrep -q '^[0-9]+$'
then
sid="$1"
echo "Notice: sid=\"$1\""
show_usage=$[$show_usage+1]
fi
if [ "$2" != "" ]
then
postersubj=$2
echo "Notice: postersubj=\"$2\""
show_usage=$[$show_usage+1]
fi
#if [ "$3" != "" ]
#then
# postercomment=$3
# echo "Notice: postercomment=\"$3\""
# show_usage=$[$show_usage+1]
#fi
if echo "$3" | egrep -q '^[1234]$'
then
posttype=$3
echo "Notice: posttype=\"$3\""
else
echo "Notice: posttype=1"
fi
if echo "$4" | egrep -q '^[0-9]+$'
then
pid=$4
else
pid=0
fi
startat=$5
echo "SHOWUSAGE $show_usage"
if [ "$show_usage" -lt "2" ]
then
echo "$0: usage $0 sid postersubj \"[posttype]\" \"[pid]\" \"[startat]\"" >&2
echo "optional arguments are in square brackets" >&2
exit 1
fi
postercomment=$(cat -)
echo "Notice: comment text read" >&2
#pid=0
#postersubj="fp bitchez VICTORY IS MINE ahahah"
#postercomment="testing using the kickass w3c fp tool from www.w3.org ($RANDOM)"
#posttype=1
op=Submit
function submit_comment_form()
{
formkey=$(curl "http://slashdot.org/comments.pl?sid=$sid&cid=0&pid=$sid&startat=$startat&threshold=0&mode=thread&commentsort=0&op=Reply" 2> /dev/null | grep 'NAME="formkey" VALUE=".*">' | sed 's/<INPUT TYPE="HIDDEN" NAME="formkey" VALUE="//g' | sed 's/">//g')
echo "Notice: form submission formkey: $formkey" >&2
echo "Notice: waiting 18 seconds for 20 second timer to run out" >&2
sleep 18
if w3c -post "http://slashdot.org/comments.pl?sid=$sid&cid=0&pid=$pid&startat=$startat&threshold=$threshold&mode=$mode&commentsort=$commentsort&op=Submit" \
-form \
'commentsort=0' \
"formkey=$formkey" \
'mode=thread' \
"op=$op" \
"pid=$pid" \
"postercomment=$postercomment" \
"postersubj=$postersubj" \
"posttype=$posttype" \
"sid=$sid" \
"startat=$startat" \
'threshold=0'
| grep -io 'Comment Submitted.'
then
echo "Notice: comment posted successfully."
else
echo "Error: comment not posted."
fi
}
submit_comment_form
---------
When posting a comment AC (which is what my planned script will do for convenience's sake) one first has to preview the comment and then submit it: they're both exactly the same operations except that for one the POST variable "op" is set to "Preview" and for the other it's "Submit". So we can just post the same variables twice.
Except...there's the formkeys. We have to generate formkeys somehow. Actually, that's quite simple. We just simulate the clicking of a Reply link and we get a valid comment submit form with a valid formkey. We fill it in, hit Preview, then get a new form with another formkey. Use that, fill it in, submit, done.
Oh, and then, there's the waiting for a smidge under 20 seconds for the lameness filter.
OK, the rest of this journal entry is going to be another experimental bash shell script:
---------
#!/bin/bash
show_usage=0
if echo "$1" | egrep -q '^[0-9]+$'
then
sid="$1"
echo "Notice: sid=\"$1\""
show_usage=$[$show_usage+1]
fi
if [ "$2" != "" ]
then
postersubj=$2
echo "Notice: postersubj=\"$2\""
show_usage=$[$show_usage+1]
fi
#if [ "$3" != "" ]
#then
# postercomment=$3
# echo "Notice: postercomment=\"$3\""
# show_usage=$[$show_usage+1]
#fi
if echo "$3" | egrep -q '^[1234]$'
then
posttype=$3
echo "Notice: posttype=\"$3\""
else
echo "Notice: posttype=1"
fi
if echo "$4" | egrep -q '^[0-9]+$'
then
pid=$4
else
pid=0
fi
startat=$5
echo "SHOWUSAGE $show_usage"
if [ "$show_usage" -lt "2" ]
then
echo "$0: usage $0 sid postersubj \"[posttype]\" \"[pid]\" \"[startat]\"" >&2
echo "optional arguments are in square brackets" >&2
exit 1
fi
postercomment=$(cat -)
echo "Notice: comment text read" >&2
#pid=0
#postersubj="fp bitchez VICTORY IS MINE ahahah"
#postercomment="testing using the kickass w3c fp tool from www.w3.org ($RANDOM)"
#posttype=1
op=Submit
function submit_comment_form()
{
formkey=$(curl "http://slashdot.org/comments.pl?sid=$sid&cid=0&pid=$sid&startat=$startat&threshold=0&mode=thread&commentsort=0&op=Reply" 2>
echo "Notice: form submission formkey: $formkey" >&2
echo "Notice: waiting 18 seconds for 20 second timer to run out" >&2
sleep 18
if w3c -post "http://slashdot.org/comments.pl?sid=$sid&cid=0&pid=$pid&startat=$startat&threshold=$threshold&mode=$mode&commentsort=$commentsort&op=Submit" \
-form \
'commentsort=0' \
"formkey=$formkey" \
'mode=thread' \
"op=$op" \
"pid=$pid" \
"postercomment=$postercomment" \
"postersubj=$postersubj" \
"posttype=$posttype" \
"sid=$sid" \
"startat=$startat" \
'threshold=0'
| grep -io 'Comment Submitted.'
then
echo "Notice: comment posted successfully."
else
echo "Error: comment not posted."
fi
}
submit_comment_form
---------
Comment posting POST data More Login
Comment posting POST data
Slashdot Top Deals