User:EsquivalienceBot/Backlog/Source
Appearance
Very rough source code.
'''
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
'''
#!/usr/bin/python
import pywikibot
from datetime import datetime
import time
import re
site = pywikibot.Site()
log_page = pywikibot.Page(site, "User:EsquivalienceBot/Backlog")
def utc_tostr():
return datetime.utcnow().strftime("%-d %B %Y %X")
def recount(page, minus, regex):
return len(re.findall(regex, page.get(force=True))) - minus
def count_bullets(page, minus):
return recount(page, minus, r"\n\*[^:]")
def count_an3():
page = "Wikipedia:Administrators' noticeboard/Edit warring"
return recount(pywikibot.Page(site, page), 0, r"==.*?\(Result:[\)\s]+?==")
def count_rpp():
page = "Wikipedia:Requests for page protection#Current requests for increase in protection level"
return recount(pywikibot.Page(site, page), 0, r"===.*?===")
def get_backlog():
log_page.text = log_page.text[:log_page.text.rfind("\n")]
pages = [("Wikipedia:Administrator intervention against vandalism", 2), ("Wikipedia:Usernames for administrator attention", 1)]
entries = []
for i in pages:
entries.append(count_bullets(pywikibot.Page(site, i[0]), i[1]))
text += "\n|-\n|" + utc_tostr() + "||" + "||".join(map(str, entries)) + "||" + str(count_an3()) + "||" + str(count_rpp()) + "||{{subst:PAGESINCAT:Candidates for speedy deletion}}" + "\n|}"
log_page.text = text
log_page.save(summary="Updating.")
get_backlog()