-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsolar_eclipse.py
executable file
·116 lines (93 loc) · 3.99 KB
/
solar_eclipse.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Solar Eclipse Bot
This bot finds all pages created for non-notable solar eclipses and turns them
into a redirect. It also updates their item on Wikidata.
"""
#
# (C) Pywikibot team, 2006-2016
# (C) Huji, 2016
#
# Distributed under the terms of the MIT license.
#
from __future__ import absolute_import, unicode_literals
#
import pywikibot
import re
import string
from pywikibot import pagegenerators
from pywikibot.bot import (
SingleSiteBot, ExistingPageBot, NoRedirectPageBot, AutomaticTWSummaryBot)
from pywikibot.tools import issue_deprecation_warning
docuReplacements = {
'¶ms;': pagegenerators.parameterHelp
}
class EclipseBot(
# Refer pywikobot.bot for generic bot classes
SingleSiteBot, # A bot only working on one site
# CurrentPageBot, # Sets 'current_page'. Processes it in treat_page method.
# # Not needed here because we have subclasses
ExistingPageBot, # CurrentPageBot which only treats existing pages
NoRedirectPageBot, # CurrentPageBot which only treats non-redirects
):
def __init__(self, generator, **kwargs):
self.availableOptions.update({
'summary': u'ربات: تبدیل صفحههای ناسرشناس به تغییرمسیر ([[ویکیپدیا:سیاست رباترانی/درخواست مجوز/HujiBot/وظیفه ۱۴|وظیفه ۱۴]])',
})
# Call constructor of the super class
super(EclipseBot, self).__init__(site=True, **kwargs)
# Handle old -dry paramter
self._handle_dry_param(**kwargs)
# Assign the generator to the bot
self.generator = generator
# Save edits without asking
self.options['always'] = True
def _handle_dry_param(self, **kwargs):
if 'dry' in kwargs:
issue_deprecation_warning('dry argument',
'pywikibot.config.simulate', 1)
# use simulate variable instead
pywikibot.config.simulate = True
pywikibot.output('config.simulate was set to True')
def treat_page(self):
text = self.current_page.text
ListPattern = r'\* \[\[(فهرست خورشیدگرفتگیهای قرن .+ میلادی|فهرست خورشیدگرفتگیهای قرن .+ پیش از میلاد|فهرست خورشیدگرفتگیهای دوران باستان)\]\]'
hasListPattern = re.search(ListPattern, text)
if hasListPattern:
newText = u'#تغییرمسیر [[%s]]' % hasListPattern.group(1)
print newText
self.put_current(newText, summary=self.getOption('summary'))
item = pywikibot.ItemPage.fromPage(self.current_page)
item.removeSitelink(site='fawiki', summary=u'Remove sitelink')
def main(*args):
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.
genFactory = pagegenerators.GeneratorFactory()
# Parse command line arguments
for arg in local_args:
# Catch the pagegenerators options
if genFactory.handleArg(arg):
continue # nothing to do here
# Take the remaining options as booleans.
# You will get a hint if they aren't pre-definded in your bot class
else:
pywikibot.output('Unknown argument(s)!')
gen = genFactory.getCombinedGenerator()
if gen:
# The preloading generator is responsible for downloading multiple
# pages from the wiki simultaneously.
gen = pagegenerators.PreloadingGenerator(gen)
# pass generator and private options to the bot
bot = EclipseBot(gen, **options)
bot.run() # guess what it does
return True
else:
pywikibot.bot.suggest_help(missing_generator=True)
return False
if __name__ == '__main__':
main()