Jump to content

User:Rick Block/wp1000

From Wikipedia, the free encyclopedia

This is a pair of scripts to generate the main namespace and all namespaces lists at WP:1000 given a csv file with the raw data (edit counts per user). Depending on your OS, you might need to replace awk with nawk.

Rick Block (talk) 20:34, July 23, 2005 (UTC)

Main namespace script

[edit]
#!/bin/bash

# $1 is the current csv file
# $2 is the output from the last time (used for positional delta)

cat $1 | grep "^en,[0-9][0-9][0-9]" | sort -r -n -t',' +1 | cat $2 - | awk '
BEGIN {
  bot["Rambot"] = 1;
  bot["D6"] = 1;
  bot["Template namespace initialisation script"] = 1;
  bot["CanisRufus"] = 1;
  bot["Robbot"] = 1;
  bot["Conversion script"] = 1;
  bot["Guanabot"] = 1;
  bot["Nobot"] = 1;
  bot["Grammarbot"] = 1;
  bot["Wikibot"] = 1;
  bot["HasharBot"] = 1;
  bot["Snobot"] = 1;
  bot["NetBot"] = 1;
  bot["FlaBot"] = 1;
  bot["JdforresterBot"] = 1;
  bot["Pearle"] = 1;

  somebot["Ram-Man"] = 1;
  somebot["KevinBot"] = 1;
  somebot["Timwi"] = 1;

  pad="    ";
  count=1;

  FS=",";

}

/<TR>/ {
  split($0,fields,"<|>|]|\\[|:|\\|");
  sub(" ","",fields[5]);
  # print " f1=" fields[1] " f2=" fields[2] " f3=" fields[3] " f4=" fields[4] " f5=" fields[5] " f6=" fields[6] " f7=" fields[7] " f8=" fields[8] " f9=" fields[9] " f10=" fields[10]
  # fields[5] is position
  # fields[8] is username
  if (fields[5] != "") {
    prevpos[fields[8]] = int(fields[5]);
  }
  
}

/^en/ {
  # $1 is language
  # $2 is mainspace edits
  # $3 is mainspace recent edits
  # $4 is non-mainspace edits
  # $5 is non-mainspace recent edits
  # $6 is current position (unused)
  # $7 is previous position (unused)
  # $8 is user
  if (bot[$8] == 1) {
    print "<TR><TD><font color=\"gray\">[[User:" $8 "|" $8 "]]</font></TD><TD align=right>" $2 "</TD><TD align=right>" $3 pad "</TD><TD> </TD></TR>"
  } else {
    if ( prevpos[$8] == "" ) {
      poschg="<font color=\"green\">new</font>"
    } else if (count == prevpos[$8]) {
      poschg="–"
    } else if (count < prevpos[$8]) {
      chg=prevpos[$8] - count
      poschg="<font color=\"green\">↑ " chg "</font>"
    } else {
      chg=count - prevpos[$8]
      poschg="<font color=\"red\">↓ " chg "</font>"
    }
    somebotchgs="";
    if (somebot[$8] == 1) {
      somebotchgs="†"
    }
    print "<TR><TD>" count " [[User:" $8 "|" $8 "]]" somebotchgs "</TD><TD align=right>" $2 "</TD><TD align=right>" $3 pad "</TD><TD>" poschg "</TD></TR>"

    count=count + 1
    if (count >= 1001) exit
  }
}
'

All namespaces script

[edit]
#!/bin/bash

# $1 is the current csv file

cat $1 | grep "^en,[0-9][0-9][0-9]" | awk '
BEGIN {
  FS=","
}
{
  total = $2 + $4
  totalrecent = $3 + $5
  if (total > 1000) {
    print total "," totalrecent "," $8
  }
}' | sort -r -n -t',' | awk '
BEGIN {
  bot["Rambot"] = 1;
  bot["D6"] = 1;
  bot["Template namespace initialisation script"] = 1;
  bot["CanisRufus"] = 1;
  bot["Robbot"] = 1;
  bot["Conversion script"] = 1;
  bot["Guanabot"] = 1;
  bot["Nobot"] = 1;
  bot["Grammarbot"] = 1;
  bot["Wikibot"] = 1;
  bot["HasharBot"] = 1;
  bot["Snobot"] = 1;
  bot["NetBot"] = 1;
  bot["FlaBot"] = 1;
  bot["JdforresterBot"] = 1;
  bot["Pearle"] = 1;

  somebot["Ram-Man"] = 1;
  somebot["KevinBot"] = 1;
  somebot["Timwi"] = 1;

  pad="    ";
  count=1;

  FS=",";
}

{
  # $1 is total edits
  # $2 is recent edits
  # $3 is user
  if (bot[$3] == 1) {
    print "<TR><TD><font color=\"gray\">[[User:" $3 "|" $3 "]]</font></TD><TD align=right>" $1 "</TD><TD align=right>" $2 pad "</TD></TR>"
  } else {
    somebotchgs="";
    if (somebot[$3] == 1) {
      somebotchgs="†"
    }
    print "<TR><TD>" count " [[User:" $3 "|" $3 "]]" somebotchgs "</TD><TD align=right>" $1 "</TD><TD align=right>" $2 pad "</TD></TR>"

    count=count + 1
    if (count >= 1001) exit
  }
}
'