User:MDanielsBot/Task A source
Jump to navigation
Jump to search
import pywikibot
import json
from datetime import datetime, timezone
def floor(num, roundto):
return num - (num % roundto);
def globaleditcount(user):
params = {
"action": "query",
"format": "json",
"meta": "globaluserinfo",
"guiuser": user.username,
"guiprop": "editcount"
}
response = pywikibot.data.api.Request(site=user.site, parameters=params).submit()
return response['query']['globaluserinfo']['editcount']
# code for other wikis omitted
wikidatawiki = pywikibot.Site('wikidata', 'wikidata');
wikidataLocalTemplatePage = pywikibot.Page(wikidatawiki, 'User:MDanielsBot/LocalEC')
wikidataGlobalTemplatePage = pywikibot.Page(wikidatawiki, 'User:MDanielsBot/GlobalEC')
# Local EC for wikidatawiki
for userpage in wikidataLocalTemplatePage.embeddedin(namespaces=2):
if userpage.depth != 0: continue;
username = userpage.title(with_ns=False)
user = pywikibot.page.User(wikidatawiki, userpage.title(with_ns=False));
localEC = user.editCount();
subpage_name = wikidataLocalTemplatePage.title() + '/' + username
subpage = pywikibot.Page(wikidatawiki, subpage_name)
# Only update every 100 edits
tol = 100;
localEC = floor(localEC, tol)
if localEC <= 1000 and username != "MDanielsBot":
continue;
if subpage.text == "" or int(subpage.text) != localEC:
subpage.put(localEC, summary="[User:MDanielsBot#Task A|Bot task A]]: Updating local edit count", botflag=True)
# Global EC for wikidatawiki
for userpage in wikidataGlobalTemplatePage.embeddedin(namespaces=2):
if userpage.depth != 0: continue;
username = userpage.title(with_ns=False)
user = pywikibot.page.User(wikidatawiki, userpage.title(with_ns=False));
globalEC = globaleditcount(user);
subpage_name = wikidataGlobalTemplatePage.title() + '/' + username
subpage = pywikibot.Page(wikidatawiki, subpage_name)
# Only update every 100 edits
tol = 100;
globalEC = floor(globalEC, tol)
if globalEC <= 5000 and username != "MDanielsBot":
continue;
if subpage.text == "" or int(subpage.text) != globalEC:
subpage.put(globalEC, summary="[User:MDanielsBot#Task A|Bot task A]]: Updating global edit count", botflag=True)