User:Rick Block/CFDindexer

Script
This is a script that generates an alphabetical index of a month's worth of WP:CFD logs. Assumes the entries are closed with the &#123;{Cfd top}} template.

Rick Block (talk) 00:20, July 31, 2005 (UTC) -
 * 1) !/bin/bash


 * 1) usage: CFDindexer month year
 * 2) example: CFDindex June 2005

MONTH=$1 YEAR=$2

WGET="/usr/bin/curl" # on a mac OS X
 * 1) WGET="wget -q -O -"   # on a linux box with wget

CFDCATS="CFDcats"
 * 1) files

if [ "$3" != "CFDcats" ]; then for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31; do echo "" echo "LOGFILE: Wikipedia:Categories for deletion/Log/$YEAR $MONTH $i" echo "DATE: $MONTH $i" $WGET "http://en.wikipedia.org/w/index.php?title=Wikipedia:Categories_for_deletion/Log/${YEAR}_${MONTH}_${i}&action=raw" done >$CFDCATS fi
 * 1) get all log articles for the given month
 * 1) get all log articles for the given month

case $MONTH in January) PREVMONTH="December"; let PREVYEAR=$YEAR-1; NEXTMONTH="February"; NEXTYEAR=$YEAR;;  February) PREVMONTH="January"; PREVYEAR=$YEAR; NEXTMONTH="March"; NEXTYEAR=$YEAR;; March) PREVMONTH="February"; PREVYEAR=$YEAR; NEXTMONTH="April"; NEXTYEAR=$YEAR;; April) PREVMONTH="March"; PREVYEAR=$YEAR; NEXTMONTH="May"; NEXTYEAR=$YEAR;; May) PREVMONTH="April"; PREVYEAR=$YEAR; NEXTMONTH="June"; NEXTYEAR=$YEAR;; June) PREVMONTH="May"; PREVYEAR=$YEAR; NEXTMONTH="July"; NEXTYEAR=$YEAR;; July) PREVMONTH="June"; PREVYEAR=$YEAR; NEXTMONTH="August"; NEXTYEAR=$YEAR;; August) PREVMONTH="July"; PREVYEAR=$YEAR; NEXTMONTH="September"; NEXTYEAR=$YEAR;; September) PREVMONTH="August"; PREVYEAR=$YEAR; NEXTMONTH="October"; NEXTYEAR=$YEAR;; October) PREVMONTH="September"; PREVYEAR=$YEAR; NEXTMONTH="November"; NEXTYEAR=$YEAR;; November) PREVMONTH="October"; PREVYEAR=$YEAR; NEXTMONTH="December"; NEXTYEAR=$YEAR;; December) PREVMONTH="November"; PREVYEAR=$YEAR; NEXTMONTH="January"; let NEXTYEAR=$YEAR+1;; esac

cat $CFDCATS | awk ' /^LOGFILE:/ { logfile = $0; sub("^LOGFILE: ","",logfile); } /^DATE:/ { date = $0; sub("^DATE: ","",date); } /^====[^=]/ { # line might be like ====Category:Airports_of_Yukon==== # or like ====Category:xxxx xFC Pro Bowl players==== # or like ===={{{2|Category:xxxx xFC Pro Bowl players}}==== cat = $0; sub("^==== *","",cat); sub(" *==== *$","",cat); sub("^$","]]",cat); sub("Category: *","Category:",cat); }

/^The result of the debate was/ { result = $0; sub("^The result of the debate was ","",result); sub("[]*[|]","",justcat);   gsub("[[][[]:Category:","Category:",justcat);    gsub("[[][[]:category:","category:",justcat);    gsub("[[][[]:","",justcat);    gsub("[[][[]","",justcat);    gsub("","",justcat);    gsub("'"'"'","",justcat);    gsub("'""'","",justcat);    gsub("<[^>]*>","",justcat);    gsub("","",justcat);    gsub("","]]",cat);    sortcat = justcat;    sub("^[cC]ategory:","",sortcat);    print sortcat "%%%%%| " cat " || " result " || " date ""  }  cat = ""; } ' | sort -f | awk -v prevmonth=$PREVMONTH -v prevyear=$PREVYEAR -v nextmonth=$NEXTMONTH -v nextyear=$NEXTYEAR ' BEGIN {  print ""  print "{| width = \"100%\""  print "|-"  print "! width=\"50%\" align=\"left\"  | &lt; " prevyear " " prevmonth ""  print "! width=\"50%\" align=\"right\" | " nextyear " " nextmonth " &gt; "  print "|}"  print " "  print "The following is an alphabetical index of decisions made at Categories for deletion."  print ""  print "{| class=\"wikitable\""  print "! Category !! Decision !! Discussion_log" }

{ print "|-" row=$0 sub("^.*%%%%%","",row) print row }

END { print "|}" }' >$MONTH