Xqt has uploaded a new change for review.
https://gerrit.wikimedia.org/r/286311
Change subject: [IMPR] use wikihistory to get main authors
......................................................................
[IMPR] use wikihistory to get main authors
Change-Id: Iccfa7105e55a58a36361bb80826b3e6a87b508c8
---
M afd-notice.py
1 file changed, 23 insertions(+), 31 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/pywikibot/bots/xqbot
refs/changes/11/286311/1
diff --git a/afd-notice.py b/afd-notice.py
index f041b34..1368c69 100644
--- a/afd-notice.py
+++ b/afd-notice.py
@@ -24,10 +24,11 @@
#
import pickle
+import re
import time
-from collections import Counter
import pywikibot
+from pywikibot.comms.http import fetch
from pywikibot import config, pagegenerators, textlib
from pywikibot.bot import SingleSiteBot
@@ -165,7 +166,7 @@
"""
Process a given page.
- Get the creator of the page and calculate the main authors.
+ Get the creator of the page and get the main authors from wikihistory.
@param pagename: page title
@type pagename: str
@@ -173,7 +174,7 @@
page = pywikibot.Page(pywikibot.Link(pagename))
if not page.exists():
return
- cnt = Counter()
+
# read the oldest_revision with content
old_rev = next(page.revisions(total=1, reverse=True, content=True))
@@ -191,23 +192,6 @@
# either he tagged the deletion request or he saw it
latest = next(page.revisions(total=1)).user
- # evtl. anonyme/unregistrierte von Zählung ausnehmen
- for rev in page.revisions():
- if rev.minor:
- cnt[rev.user] += 0.2
- else:
- cnt[rev.user] += 1
-
- s = sum(cnt.values())
- s2 = sum(i ** 2 for i in cnt.values())
- n = float(len(cnt))
- x_ = s / n
- # avg + stdabw
- # faktor von 1 auf 1,5 erhöht für bessere Trennschärfe
- # (siehe Bem. von Gestumblindi)
- limit = max(5, (s2 / n - x_ ** 2) ** 0.5 * 1.5 + x_)
- # main, main_cnt = cnt.most_common(1)[0]
-
# inform creator
if creator and creator != latest and creator not in self.ignoreUser:
user = pywikibot.User(self.site, creator)
@@ -217,18 +201,26 @@
self.inform(user, page=page.title(), action=u'angelegte')
# inform main authors
- for main, main_cnt in cnt.most_common(7):
- if main_cnt < limit:
+ url = ('https://tools.wmflabs.org/wikihistory/dewiki/getauthors.php?'
+ 'page_id=%s' page._pageid)
+ r = fetch(url)
+ if r.status not in ('200', ):
+ pywikibot.warning('wikihistory request status is ' + r.status)
+ return # TODO: try again?
+ pattern = '>(?P<author>.+?)</a>\s\((?P<percent>\d{1,3})&' for
main, main_cnt in re.findall(pattern, r.content):
+ for main, main_cnt in re.findall(pattern, r.content):
+ if ' weitere' in main:
break
- if main != latest and main != creator and \
- main not in self.ignoreUser:
- user = pywikibot.User(self.site, main)
- if user.isRegistered() and not (user.isBlocked() or
- 'bot' in user.groups()):
- pywikibot.output(u'>>> Main author %s with %d Edits'
- % (main, main_cnt))
- self.inform(user, page=page.title(),
- action=u'stark überarbeitete')
+ if main == latest or main == creator or main in self.ignoreUser:
+ continue
+ user = pywikibot.User(self.site, main)
+ if user.isRegistered() and not (user.isBlocked() or
+ 'bot' in user.groups()):
+ pywikibot.output('>>> Main author %s with %d % edits'
+ % (main, main_cnt))
+ self.inform(user, page=page.title(),
+ action='stark überarbeitete')
+
def inform(self, user, **param):
"""
--
To view, visit https://gerrit.wikimedia.org/r/286311
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iccfa7105e55a58a36361bb80826b3e6a87b508c8
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/bots/xqbot
Gerrit-Branch: master
Gerrit-Owner: Xqt <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits