diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-01-24 21:07:14 -0500 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2014-01-24 21:07:14 -0500 |
commit | 84d268f0d9c7efb267118e1cca54366bead0f58e (patch) | |
tree | a68ac617b8f609819bb8a3f034c1cf167a68bb7a /show-edit-counts.rb | |
parent | cd1997f34e03fe9e338d4f696d8c66dec605cca4 (diff) |
touch up
Diffstat (limited to 'show-edit-counts.rb')
-rwxr-xr-x | show-edit-counts.rb | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/show-edit-counts.rb b/show-edit-counts.rb index d20a812..4abd310 100755 --- a/show-edit-counts.rb +++ b/show-edit-counts.rb @@ -3,42 +3,57 @@ load 'mwapi.rb' require 'yaml' +require 'pp' mw = MWApi.new('https://wiki.parabolagnulinux.org/api.php') credentials = YAML.load_file('credentials.yml') mw.login(credentials['username'], credentials['password']) +userqueue = [] + aufrom = '' while not aufrom.nil? do - audata = mw.query(:list => :allusers, :aulimit => 200, :aufrom => aufrom, :auprop => 'blockinfo') + audata = mw.query( + :list => :allusers, + :auprop => 'blockinfo|editcount|registration', + :aulimit => 5000, + :aufrom => aufrom) for user in audata['query']['allusers'] if user['blockid'].nil? - deleted_edits = 0 # XXX actually is the number of deleted pages edited, not number of edits - existing_edits = 0 - drcontinue = '' - while not drcontinue.nil? - drdata = mw.query(:list => :deletedrevs, :druser => user['name'], :drlimit => 200) - deleted_edits += drdata['query']['deletedrevs'].length - drcontinue = nil - end - uccontinue = '' - while not uccontinue.nil? - ucdata = mw.query(:list => :usercontribs, :ucuser => user['name'], :uclimit => 200, :uccontinue => uccontinue) - existing_edits += ucdata['query']['usercontribs'].length - if ucdata['query-continue'].nil? - uccontinue = nil - else - uccontinue = ucdata['query-continue']['usercontribs']['uccontinue'] - end + if user['editcount'] == 0 + # optimize 0 edits means we don't need to count how many aren't deleted + print "name: #{user['name']}\tregistration: #{user['registration']}\ttotal_editcount: 0\texisting_editcount: 0\n" + else + # queue this user for counting how many live edits they have + userqueue.push(user) end - print "Username: #{user['name']}\tdeleted: #{deleted_edits}\texisting: #{existing_edits}\n" else - print "Username: #{user['name']}\tblockreason: #{user['blockreason']}\n" + print "name: #{user['name']}\tregistration: #{user['registration']}\tblockreason: #{user['blockreason']}\n" + end + end + aufrom = (audata['query-continue'].nil?) ? nil : audata['query-continue']['allusers']['aufrom'] +end + +userqueue.each_slice(5000) do |userlist| + contribcount = {} + uccontinue = '' + while not uccontinue.nil? + query = { + :list => :usercontribs, + :ucuser => (userlist.map{|u| u['name']}).join('|'), + :uclimit => 5000, + } + if uccontinue.length > 0 + query.merge!({:uccontinue => uccontinue}) + end + ucdata = mw.query(query) + ucdata['query']['usercontribs'].each do |contrib| + contribcount[contrib['user']] ||= 0 + contribcount[contrib['user']] += 1 end + uccontinue = (ucdata['query-continue'].nil?) ? nil : ucdata['query-continue']['usercontribs']['uccontinue'] end - if audata['query-continue'].nil? - aufrom = nil - else - aufrom = audata['query-continue']['allusers']['aufrom'] + userlist.each do |user| + print "name: #{user['name']}\tregistration: #{user['registration']}\ttotal_editcount: #{user['editcount']}\texisting_editcount: #{contribcount[user['name']]}\n" end end |