User:Rick Block/CFDindexer
Appearance
Script
[edit]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 {{Cfd top}} template.
Rick Block (talk) 00:20, July 31, 2005 (UTC)
#!/bin/bash # usage: CFDindexer month year # example: CFDindex June 2005 MONTH=$1 YEAR=$2 WGET="/usr/bin/curl" # on a mac OS X # WGET="wget -q -O -" # on a linux box with wget # files CFDCATS="CFDcats" # # get all log articles for the given month 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 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("}}}$","]]",cat); sub("Category: *","Category:",cat); } /^The result of the debate was/ { result = $0; sub("^The result of the debate was ","",result); sub("[[][[][uU]ser.*","",result); sub(".mdash;.*","",result); sub(" [^a-zA-Z0-9]+ <small.*","",result); sub("[. -]*$","",result); if (cat != "") { justcat = cat; gsub("[[][[]:[cC]ategory:[^|[]*[|]","",justcat); gsub("[[][[]:Category:","Category:",justcat); gsub("[[][[]:category:","category:",justcat); gsub("[[][[]:","",justcat); gsub("[[][[]","",justcat); gsub("]]","",justcat); gsub("'"'''"'","",justcat); gsub("'"''"'","",justcat); gsub("<[^>]*>","",justcat); gsub("{{cl[|]","Cat:",justcat); gsub("}}","",justcat); gsub("{{cl[|]","[[:Category:",cat); gsub("}}","]]",cat); sortcat = justcat; sub("^[cC]ategory:","",sortcat); print sortcat "%%%%%| " cat " || " result " || [[" logfile "#" justcat "|" date "]]" } cat = ""; } ' | sort -f | awk -v prevmonth=$PREVMONTH -v prevyear=$PREVYEAR -v nextmonth=$NEXTMONTH -v nextyear=$NEXTYEAR ' BEGIN { print "<div class=\"boilerplate metadata vfd\" style=\"background-color: #F3F9FF; margin: 0 auto; padding: 0 1px 0 0; border: 1px solid #AAAAAA; font-size:10px\">" print "{| width = \"100%\"" print "|-" print "! width=\"50%\" align=\"left\" | <font color=\"gray\"><</font> [[Wikipedia:Categories for deletion/Archive debates/" prevyear " " prevmonth " index|" prevyear " " prevmonth "]]" print "! width=\"50%\" align=\"right\" | [[Wikipedia:Categories for deletion/Archive debates/" nextyear " " nextmonth " index|" nextyear " " nextmonth "]] <font color=\"gray\">></font>" print "|}" print "</div>" print "The following is an alphabetical index of decisions made at [[Wikipedia:Categories for deletion]]." print "" print "{| class=\"wikitable\"" print "! Category !! Decision !! Discussion_log" } { print "|-" row=$0 sub("^.*%%%%%","",row) print row } END { print "|}" }' >$MONTH