Skip to content

Instantly share code, notes, and snippets.

@AleksandrT
Last active December 25, 2015 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AleksandrT/7038921 to your computer and use it in GitHub Desktop.
Save AleksandrT/7038921 to your computer and use it in GitHub Desktop.
Wikiuploadbot
#!/bin/bash
# GLOBAL #
#-----------------------#
WIKIAPI="http://commons.wikimedia.org/w/api.php"
DEBUG=0
UNAME=""
UPASS=""
TOKEN=""
COOKIES="wikic"
USERAGENT="Curl_Shell_Script_SpreadthesignBot/0.3"
# DEBUG #
#-----------------------#
if [ ${DEBUG} -eq 0 ]
then
echo "NO DEBUG MODE"
else
echo "DEBUG MODE"
fi
# Login 1 (2) #
#-----------------------#
echo "Logging in 1/(2)..."
CR=$(curl -S \
--location \
--retry 2 \
--retry-delay 5\
--cookie $COOKIES \
--cookie-jar $COOKIES \
--user-agent $USERAGENT \
--keepalive-time 60 \
--header "Accept-Language: en-us" \
--header "Connection: keep-alive" \
--compressed \
--data-urlencode "lgname=${UNAME}" \
--data-urlencode "lgpassword=${UPASS}" \
--request "POST" "${WIKIAPI}?action=login&format=txt")
CR2=($CR)
if [ "${CR2[9]}" = "[token]" ]; then
TOKEN=${CR2[11]}
echo "Logging in (1/2)...Complete"
echo "Token="$TOKEN
else
echo "Login part 1 failed."
#echo $CR >
exit
fi
# Login 2 (2) #
#-----------------------#
echo "Logging in (2/2)..."
CR=$(curl -S \
--location \
--cookie $COOKIES \
--cookie-jar $COOKIES \
--user-agent $USERAGENT \
--keepalive-time 60 \
--header "Accept-Language: en-us" \
--header "Connection: keep-alive" \
--compressed \
--data-urlencode "lgname=${UNAME}" \
--data-urlencode "lgpassword=${UPASS}" \
--data-urlencode "lgtoken=${TOKEN}" \
--request "POST" "${WIKIAPI}?action=login&format=txt")
CR2=($CR)
if [ "${CR2[8]}" = "Success" ]; then
echo "Successfully logged 2 in as $UNAME."
else
echo "Login part 2 failed."
exit
fi
# GET EDIT TOKEN #
#-----------------------#
CR=$(curl -S \
--location \
--cookie $COOKIES \
--cookie-jar $COOKIES \
--user-agent $USERAGENT \
--keepalive-time 60 \
--header "Accept-Language: en-us" \
--header "Connection: keep-alive" \
--compressed \
--request "POST" \
"${WIKIAPI}?action=query&prop=info|revisions&titles=Foo&intoken=edit&format=txt")
CR2=($CR)
total=${#CR2[*]}
for (( i=0; i<=$(( $total -1 )); i++ ))
do
if [ ${CR2[$i]} = "[edittoken]" ]
then
TOKEN=""
TOKEN=${CR2[$i+2]}
fi
done
if [ ${TOKEN} != "" ]; then
echo "Successfully fechted edittoken"
else
echo "Failed to fetch edit token!"
exit
fi
# READY TO UPLOAD #
#-------------------------------#
text="{{int:filedesc}}== {{Information |description={{ English|1=Large evergreen tropical tree cultivated for its large oval fruit}} |date=2010-05-06 |source={{STS-link|9994}} |author={{Spread the sign}} |permission={{STS-cooperation}} |other_versions= |other_fields= }}[[category:Media contributed by Spread the sign]]"
CR=$(curl -S \
--location \
--cookie $COOKIE \
--cookie-jar $COOKIE \
--user-agent $USERAGENT \
--keepalive-time 60 \
--header "Accept-Language: en-us" \
--header "Connection: keep-alive" \
--header "Expect:" \
--header "Accept-Encoding: gzip" \
--compressed \
--data-urlencode "filename=bho-mango-spreadthesign-9994.ogv" \
--data-urlencode "text=${text}" \
--data-urlencode "token=${TOKEN}" \
--data-urlencode "file=@/..../9994.ogv" \
--request "POST" "${WIKIAPI}?action=upload&" )
CR2=($CR)
read -p "Done ..."
echo ${#CR2[*]} > wiki.log
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment