-
Notifications
You must be signed in to change notification settings - Fork 1
/
patrol.py
executable file
·91 lines (74 loc) · 2.59 KB
/
patrol.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/python3
"""
Modified pykibots defualt bot simple.py
Takes user as input and patrols their edits
Use global -simulate option for test purposes. No changes to live wiki
will be done.
"""
#
# (C) Drono 2022
#
import pywikibot
from pywikibot import pagegenerators
from pywikibot.bot import (
BaseBot,
)
# This is required for the text that is shown when you run this script
# with the parameter -help.
docuReplacements = {'¶ms;': pagegenerators.parameterHelp} # noqa: N816
class BasicBot(BaseBot):
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.site = pywikibot.Site()
def treat(self, page):
"""Load the given page, do some changes, and save it."""
rcid = page['rcid']
list(self.site.patrol(rcid))
print(page['title'])
def main(*args: str) -> None:
"""
Process command line arguments and invoke bot.
If args is an empty list, sys.argv is used.
:param args: command line arguments
"""
options = {}
# Process global arguments to determine desired site
local_args = pywikibot.handle_args(args)
# This factory is responsible for processing command line arguments
# that are also used by other scripts and that determine on which pages
# to work on.
gen_factory = pagegenerators.GeneratorFactory()
# Process pagegenerators arguments
local_args = gen_factory.handle_args(local_args)
# Parse your own command line arguments
user = ''
for arg in local_args:
if arg.startswith('-puser'):
user = arg[len('-puser '):]
arg, sep, value = arg.partition(':')
option = arg[1:]
#if option in ('user'):
# if not value:
# pywikibot.input('Please enter a value for ' + arg)
# options[option] = value
# take the remaining options as booleans.
# You will get a hint if they aren't pre-defined in your bot class
#else:
# options[option] = True
# The preloading option is responsible for downloading multiple
# pages from the wiki simultaneously.
#gen = gen_factory.getCombinedGenerator(preload=True)
if not user:
print("patrol.py > Please specify user: -puser=User")
return
site = pywikibot.Site()
gen = site.recentchanges(user=user, patrolled=False)
if gen:
# pass generator and private options to the bot
bot = BasicBot(generator=gen, **options)
bot.treat_page_type = dict
bot.run() # guess what it does
else:
pywikibot.bot.suggest_help(missing_generator=True)
if __name__ == '__main__':
main()