-
Notifications
You must be signed in to change notification settings - Fork 9
/
wikidata_bot_requests.py
71 lines (64 loc) · 2.85 KB
/
wikidata_bot_requests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Archive closed bot requests
# Mike Peel 11-Oct-2021 v1 - start
import pywikibot
import numpy as np
import time
import string
from pywikibot import pagegenerators
from pywikibot.data import api
import urllib
import random
from datetime import datetime
# Sites
wikidata_site = pywikibot.Site("wikidata", "wikidata")
repo = wikidata_site.data_repository() # this is a DataSite object
# Get the current archive page
archivepagename = 'Wikidata:Requests for permissions/RfBot/'+datetime.now().strftime('%B')+' '+datetime.now().strftime('%Y')
archivepage = pywikibot.Page(wikidata_site, archivepagename)
newarchivepage = archivepage.text
if newarchivepage == '':
newarchivepage = "{{DEFAULTSORT:*Bot "+datetime.now().strftime('%Y')+" "+datetime.now().strftime('%m')+"}}\n{{archive|category=Archived requests for permissions}}\n= Successful requests =\n\n= Unsuccessful requests =\n"
# Get the list of open bot requests
listpage = pywikibot.Page(wikidata_site, 'Wikidata:Requests for permissions/Bot')
newbotpage = listpage.text
lines = listpage.text.splitlines()
# Now let's run through the list and see what has been approved or withdrawn
for line in lines:
if ('Wikidata:Requests for permissions/Bot' in line or 'Wikidata:Requests_for_permissions/Bot' in line) and 'Header' not in line:
botpagetitle = line.strip().replace('{{','').replace('}}','')
print(botpagetitle)
botpage = pywikibot.Page(wikidata_site, botpagetitle)
if '{{approved}}' in botpage.text.lower():
try:
newarchivepage = newarchivepage.replace('= Successful requests =','= Successful requests =\n* ' + line.replace('{','[').replace('}',']'))
newbotpage = newbotpage.replace(line+'\n', '')
except:
print("That didn't work")
exit()
null = 0
if '{{withdrawn}}' in botpage.text.lower() or '{{not done|withdrawn}}' in botpage.text.lower() or '{{not done|disapproved}}' in botpage.text.lower():
try:
newarchivepage = newarchivepage.replace('= Unsuccessful requests =','= Unsuccessful requests =\n* ' + line.replace('{','[').replace('}',']'))
newbotpage = newbotpage.replace(line+'\n', '')
except:
print("That didn't work")
exit()
null = 0
if '{{not done}}' in botpage.text.lower():
try:
newarchivepage = newarchivepage.replace('= Unsuccessful requests =','= Unsuccessful requests =\n* ' + line.replace('{','[').replace('}',']'))
newbotpage = newbotpage.replace(line+'\n', '')
except:
print("That didn't work")
exit()
null = 0
# Do some last tidying up
newbotpage = newbotpage.replace('Requests_for_permissions','Requests for permissions')
newbotpage = newbotpage.replace('\n\n\n','\n')
# And save things
archivepage.text = newarchivepage
archivepage.save('Archiving from [[Wikidata:Requests for permissions/Bot]]')
listpage.text = newbotpage
listpage.save('Archiving closed requests to [['+archivepagename+']]')