User:Jpatokal/StatScript

From Wikivoyage
Jump to navigation Jump to search

StatScript's miserable lot in life is to keep Project:Multilingual statistics up to date without too much manual labor on (WT-en) my part.

Script[edit]

Written in luvvly-jubbly awk, also requires wget. Now uses Mediawiki's internal raw statistics.

BEGIN {
  LIST="en fr ro de sv ja nl pt es pl it"

  split(LIST, list)
  for(i in list) {
    #print list[i]
    cmd = "wget -O " list[i] " 'http://wikivoyage.org/wiki/" list[i] "/index.php?title=Special:Statistics&action=raw'; sleep 3"
    system(cmd) 
    ARGV[i]=list[i]
    n++
  }
  ARGC=++n
}
 
/total=/ { split($0, fields, ";")
           split(fields[2], values, "=")
           num[j++]=values[2]
           total+=values[2] }

END {
  CONVFMT="%.2f"
  print "|-"
  printf "| " strftime("%d %b %Y") " "
  for (i=0;i<j;i++) {
    printf "|| " num[i] " (" (100*num[i])/total "%) "
  }
  printf "|| " total
}

Output[edit]

|-
| 06 Jul 2006 || 9872 (61.76%) || 1151 (7.20%) || 482 (3.02%) || 2382 (14.90%) || 376 (2.35%) || 857 (5.36%) || 115 (0.72%) || 200 (1.25%) || 294 (1.84%) || 63 (0.39%) || 193 (1.21%) || 15985