User:Luasóg bot/scripts/stv ballot

From WikiProjectMed
Jump to navigation Jump to search

function stripSTVBallot(pageContents){ // * {{stv-ballot|A=0|B=0|C=2|D=1|E=3|F=0|-- Evertype· lines = pageContents.split("\n"); var ballots = new Array(); for (line in lines){ if (typeof lines[line] == "string") { // if (lines[line].match(/\*[ ]*\{\{stv-ballot[\|ABCDEF=1234560]+\|[.]*/)) alert(lines[line]); if (lines[line].match(/\*[ ]*\{\{[ ]*stv-ballot[ ]*(\|[ ]*[ABCDEF][ ]*=[ ]*[1234560][ ]*)+\|./)) { // valid ballot var array = lines[line].split("|"); ballot = new Object(); for (var element in array){ if(typeof array[element] == "string" && array[element].match(/[ABCDEF]=[123456]/)){ ballot[array[element].substr(2,1)] = array[element].substr(0,1).toUpperCase(); } if(typeof array[element] == "string" && array[element].match(/\[\[User([ _]talk)?:/)){ ballot.user = array[element].split(":")[array[element].split(":").length-1]; break; } } ballots.push(ballot); }; if (lines[line].match(/\*[ ]*<[ ]*s(trike)?[ ]*>[ ]*\{\{[ ]*stv-ballot[ ]*(\|[ ]*[ABCDEF][ ]*=[ ]*[1234560][ ]*)+\|./)) { // striked out ballot var array = lines[line].split("|"); ballot = new Object(); for (var element in array){ if(typeof array[element] == "string" && array[element].match(/\[\[User([ _]talk)?:/)){ ballot.user = array[element].split(":")[array[element].split(":").length-1]; break; } } ballots.push(ballot); }; } }

candidates = new Object() candidates.A = 1; candidates.B = 2; candidates.C = 3; candidates.D = 4; candidates.E = 5; candidates.F = 6; output = "6 1\n"; for (var ballot = 0; ballot < ballots.length; ballot++){ output += "1 "; for (var pref=1; pref<=6 && ballots[ballot][pref] != undefined; pref++){ output += candidates[ballots[ballot][pref]] + " "; } // output += "0\t\t"+ballots[ballot].user+"\n"; output += "0\n"; } output += "0\n\"A\"\n\"B\"\n\"C\"\n\"D\"\n\"E\"\n\"F\"\n\"Poll on Ireland article names\"\n"; trace(output); }

getContentsOfPage("Wikipedia:WikiProject Ireland Collaboration/Poll on Ireland article names", stripSTVBallot);