User:Xcbot/source


 * 1) This rather sad script is released into the public domain ##
 * 2) by its author, James Pearson (Xiong Chiamiov)             ##
 * 1) by its author, James Pearson (Xiong Chiamiov)             ##


 * 1) ! /bin/bash

wget http://en.wikipedia.org/w/index.php?title=Special:Imagelist\&offset=$(date +%Y%m%d%H%M%S --date=-7days)\&limit=5\&sort=img_timestamp\&desc=1 -O imagelist -T 15 --waitretry=15
 * 1) get list of images
 * 2) $(date +%Y%m%d%H%M%S --date=-7days) is current date minus 7 days

sed -n '/TablePager_col_img_name/p' imagelist > imagelist2 sed -e 's/.*http/http/g' imagelist2 > imagelist sed -e 's/".*$//g' imagelist > imagelist2 egrep 'jpg|JPG|png|PNG' imagelist2> imagelist
 * 1) extract out images from file
 * 2) get only the lines that have images in them
 * 1) cut the crap before the image address
 * 1) and after it
 * 1) then remove anything that's not a jpg or png

Lines=0 exec 3<> imagelist while read line <&3 do { a[$Lines]=$line #echo ${a[$Lines]} (( Lines++ )); } done exec 3>&-
 * 1) put images in an array

echo "-" echo "Number of lines read = $Lines"

mindiff=25600 # 25kB
 * 1) this is the minimum difference in file size between old and new to upload new version

for i in "${a[@]}" do { echo echo $i

wget $i -P wp_temp -T 15 --waitretry=15 # get the image and put it in temp folder

oldsize=$(stat -c%s wp_temp/*) # get the size of the image declare -i oldsize # make sure it's evaluated as an integer

if JPG) then jpegoptim -t wp_temp/* filesize=$(stat -c%s wp_temp/*) # get the size of the image declare -i filesize # make sure it's evaluated as an integer if (( ("$oldsize" - "$filesize") > "$mindiff" )) then python upload.py -log -noverify -keep -putthrottle:15 wp_temp/* "losslessly optimized using jpegoptim" else echo echo "not optimized" fi

elif PNG) then optipng wp_temp/*

filesize=$(stat -c%s wp_temp/*) # get the size of the image declare -i filesize # make sure it's evaluated as an integer if (( ("$oldsize" - "$filesize") > "$mindiff" )) then python upload.py -log -noverify -keep -putthrottle:15 wp_temp/* "losslessly optimized using optipng" else echo echo "not optimized" fi fi

rm wp_temp/* # remove the image we were working on echo } done

rm imagelist*
 * 1) clean up

exit 0