-
Notifications
You must be signed in to change notification settings - Fork 0
/
followlive.py
546 lines (483 loc) · 18.7 KB
/
followlive.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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Script to follow new articles on a wikipedia and flag them
with a template or eventually blank them.
There must be A LOT of bugs ! Use with caution and verify what
it is doing !
"""
#
# (C) Pywikipedia team, 2005-2013
#
# Distributed under the terms of the MIT license.
#
__version__='$Id$'
import sys
import datetime, time
import traceback
import wikipedia as pywikibot
import editarticle
__metaclass__ = type
# The question asked
question = u"""(multiple numbers delimited with ',')
b) blank page
e) edit page
d) delete page (need sysop right)
q) quit cleaningbot
Enter) OK
What is it? """
# templates that can be used followed by the message used as comment
# templates contains list of languages code
# languages code contains list of templates to be used
# templates contains a message and its position
templates = {
'ar': {
'{{شطب}}': {
'msg': 'وسم مساعد بالبوت: هذا المقال ينبغي حذفه',
'pos': 'top'},
'{{تنظيف}}': {
'msg': 'وسم مساعد بالبوت: هذا المقال يحتاج للتنظيف',
'pos': 'top'},
'{{بذرة}}': {
'msg': 'وسم مساعد بالبوت: هذا المقال بذرة',
'pos': 'bottom'},
'{{ويكي}}': {
'msg': 'وسم مساعد بالبوت: هذا المقال يحتاج إلى التنسيق بضيغة الويكي حسب [[ويكيبيديا:دليل الأسلوب|دليل الأسلوب]]',
'pos': 'top'},
},
'en': {
'{{db-reason}}': {
'msg': 'Robot-assisted tagging: this article should be deleted',
'pos': 'top'},
'{{cleanup}}': {
'msg': 'Robot-assisted tagging: this article need cleanup',
'pos': 'top'},
'{{stub}}': {
'msg': 'Robot-assisted tagging: this article is a stub',
'pos': 'bottom'},
'{{uncategorized}}': {
'msg': 'Robot-assisted tagging: This article needs to be [[Wikipedia:Categorization|categorized]]',
'pos': 'top'},
'{{notability}}': {
'msg': 'Robot-assisted tagging: the [[Wikipedia:Notability|notability]] of this article is unclear.',
'pos': 'top'},
'{{not verified}}': {
'msg': 'Robot-assisted tagging: this article needs to be checked for factuality.',
'pos': 'top'},
'{{copyedit}}': {
'msg': 'Robot-assisted tagging: the writing of this article needs to be [[Wikipedia:How to copy-edit|copyedited]] and improved.',
'pos': 'top'},
'{{unreferenced}}': {
'msg': 'Robot-assisted tagging: this article needs [[Wikipedia:Citing sources|references]] so it can be verified.',
'pos': 'bottom'},
'{{wikify}}': {
'msg': 'Robot-assisted tagging: this article needs to be wikified per the [[Wikipedia:Manual of Style|Manual of Style]]',
'pos': 'top'},
},
'ia': {
'{{Eliminar}}': {
'msg': 'Assistite per robot: iste articulo debe esser eliminate',
'pos': 'top'},
'{{Revision}}': {
'msg': 'Assistite per robot: iste articulo require revision',
'pos': 'top'},
'{{Stub}}': {
'msg': 'Assistite per robot: iste articulo es in stato embryonic',
'pos': 'bottom'},
},
'fr': {
u'{{suppression}}': {
'msg': u'à l\'aide du robot: cet article devrait être supprimé',
'pos': 'top'},
u'{{à vérifier}}': {
'msg': u'à l\'aide du robot: cet article est à vérifier',
'pos': 'top'},
u'{{ébauche}}': {
'msg': u'à l\'aide du robot: cet article est une ébauche',
'pos': 'top'},
},
'he': {
u'{{מחק}}': {
'msg': u'יש למחוק ערך זה',
'pos': 'top'
},
u'{{לשכתב}}': {
'msg': u'ערך זה דורש שכתוב',
'pos': 'top'
},
u'{{קצרמר}}': {
'msg': u'ערך זה הוא קצרמר',
'pos': 'bottom'
},
u'{{הבהרת חשיבות}}': {
'msg': u'חשיבותו של ערך זה אינה ברורה.',
'pos': 'top'
},
u'{{עריכה}}': {
'msg': u'ערך זה דורש עריכה',
'pos': 'top'},
},
'ia': {
u'{{Eliminar}}': {
'msg': u'Iste articulo debe esser eliminate',
'pos': 'top'
},
u'{{Revision}}': {
'msg': u'Iste articulo require revision',
'pos': 'top'
},
u'{{Stub}}': {
'msg': u'Iste articulo es in stato embryonic',
'pos': 'bottom'
},
},
'nl': {
u'{{weg}}': {
'msg': '{weg}',
'pos': 'top'
},
u'{{nuweg}}': {
'msg': '{nuweg}',
'pos': 'top'
},
u'{{wiu}}': {
'msg': '{wiu}',
'pos': 'top'
},
u'{{beg}}': {
'msg': '{beg}',
'pos': 'bottom'
},
u'{{wikify}}': {
'msg': '{wikify}',
'pos': 'top'
},
u'{{wb}}': {
'msg': '{wb}',
'pos': 'top'
},
},
'pl': {
u'{{ek}}': {
'msg': u'[[Kategoria:Ekspresowe kasowanko|ek]]',
'pos': 'top'
},
u'{{dopracować}}': {
'msg': u'Dopracować',
'pos': 'top'
},
u'{{linki}}': {
'msg': u'Linki wewnętrzne do dodania',
'pos': 'top'
},
u'{{źródła}}': {
'msg': u'W artykule brakuje źródeł',
'pos': 'top'
},
u'{{stub}}': {
'msg': u'stub (zalążek)',
'pos': 'bottom'
},
},
'pt': {
u'{{wikificar}}': {
'msg': 'Assistida por bot: {{wikificar}}',
'pos': 'top'},
u'{{reciclar}}': {
'msg': 'Assistida por bot: {{reciclar}}',
'pos': 'top'},
u'{{lixo|~~~~}}': {
'msg': 'Assistida por bot: {{lixo}}',
'pos': 'top'},
u'{{revisão}}': {
'msg': 'Assistida por bot: {{revisão}}',
'pos': 'top'},
u'{{impróprio}}': {
'msg': 'Assistida por bot: {{impróprio}}',
'pos': 'top'},
u'{{apagar vaidade}}': {
'msg': 'Assistida por bot: {{apagar vaidade}}',
'pos': 'top'},
},
'sv': {
u'{{radera}}': {
'msg': u'Robotkoll: Artikeln bör raderas',
'pos': 'top'},
u'{{städa}}': {
'msg': u'Robotkoll: Artikeln bör städas',
'pos': 'top'},
u'{{stub}}': {
'msg': u'Robotkoll: Artikeln är en stubbe',
'pos': 'bottom'},
u'{{subst:relevanskontroll}}': {
'msg': u'Robotkoll: Artikeln bör kollas mot [[WP:REL|Wikipedias relevanskriterier]].',
'pos': 'top'},
u'{{verifieras}}': {
'msg': u'Robotkoll: Artikeln bör verifieras',
'pos': 'top'},
u'{{språkvård}}': {
'msg': u'Robotkoll: Artikeln bör språkvårdas',
'pos': 'top'},
u'{{Källor}}': {
'msg': u'Robotkoll: Artikeln behöver källor',
'pos': 'bottom'},
u'{{wikify}}': {
'msg': u'Robotkoll: Artikeln behöver wikifieras',
'pos': 'top'},
},
'zh': {
u'{{Delete}}': {
'msg': u'機器人掛上模板: 本文應被刪除。',
'pos': 'top'},
u'{{subst:Cleanup/auto}}': {
'msg': u'機器人掛上模板: 本文需清理',
'pos': 'top'},
u'{{subst:Uncategorized/auto}}': {
'msg': u'機器人掛上模板: 本頁需要適當的頁面分類',
'pos': u'bottom'},
u'{{subst:Notability/auto}}': {
'msg': u'機器人掛上模板: 本條目主題未突顯其知名度或顯著性',
'pos': 'top'},
u'{{subst:refimprove/auto}}': {
'msg': u'機器人掛上模板: 本條目参考文献不足',
'pos': 'top'},
u'{{copyedit}}': {
'msg': u'機器人掛上模板: 本條目或段落需要校對',
'pos': 'top'},
u'{{subst:Unreferenced/auto}}': {
'msg': u'機器人掛上模板: 本條目沒有列出任何參考或來源',
'pos': 'top'},
u'{{subst:wikify/auto}}': {
'msg': u'機器人掛上模板: 本條目需要維基化',
'pos': 'top'},
u'{{subst:Notchinese/auto}}': {
'msg': u'機器人掛上模板: 本条目没有翻译',
'pos': 'top'},
u'{{subst:Substub/auto}}': {
'msg': u'機器人掛上模板: 小小作品',
'pos': 'top'},
u'{{stub}}': {
'msg': u'機器人掛上模板: 本文是小作品',
'pos': 'bottom'},
u'{{notchinesetitle}}': {
'msg': u'機器人掛上模板: 本条目名称需要翻译成中文',
'pos': 'top'},
u'{{subst:Translating/auto}}': {
'msg': u'機器人掛上模板: 本条目没有翻译完成',
'pos': 'top'},
u'{{fansite}}': {
'msg': u'機器人掛上模板: 本条目內容類似愛好者網站',
'pos': 'top'},
},
}
# Message used when blanking an article
blanking = {
'ar': u'تم الإفراغ، المحتوى كان "%s"',
'en': u'blanked, content was "%s"',
'fr': u'blanchit, le contenu était "%s"',
'he': u'רוקן, תוכן היה "%s"',
'pl': u'wyczyszczony - zawartością było "%s"',
'pt': u'em branco - conteúdo é "%s"',
'sv': u'Robot tar bort innehåll på grund av "%s"',
'zh': u'清空,之前的內容是 "%s"',
}
# do nothing if this is in it
done = {
'ar': (u'{{شطب}}', u'{{حذف}}', u'{{خرق}}'),
'en': ('{{VfD}}', '{{AfD}}', '{{AfD1}}', '{{cleanup}}', '{{nonsense}}',
'{{deletedpage}}', '{{db-reason}}', '{{notability}}',
'{{not verified}}', '{{unreferenced}}', '{{db-empty}}',
'{{db-nocontext}}', '{{db-foreign}}', '{{db-notenglish}}',
'{{db-nocontent}}', '{{db-blankcsd}}', '{{db-transwiki}}',
'{{db-attack}}', '{{db-band}}', '{{db-club}}', '{{db-bio}}',
'{{db-bio-notenglish}}', '{{db-inc}}', '{{db-bio-photo}}',
'{{db-catempty}}', '{{db-c2}}', '{{db-catfd}}', '{{badname}}',
'{{db-pagemove}}', '{{db-nonsense}}', '{{db-spam}}',
'{{db-copyvio}}', '{{db-test}}', '{{db-vandalism}}', '{{db-repost}}',
'{{db-banned}}', '{{db-histmerge}}', '{{db-move}}', '{{db-g6}}',
'{{db-afd}}', '{{db-disambig}}', '{{db-authora}}', '{{db-author}}',
'{{db-blanked}}', '{{csd:g7}}', '{{db-talk}}', '{{db-botnomain}}',
'{{db-redundantimage}}', '{{db-noimage}}', '{{db-noncom}}',
'{{db-ccnoncom}}', '{{db-unksource}}', '{{db-norat}}',
'{{db-badfairuse}}', '{{duplicate}}', '{{db-meta}}',
'{{db-emptyportal}}', '{{db-redirnone}}', '{{db-rediruser}}',
'{{db-redirtypo}}', '{{csd-c3}}', '{{cc-by-nc-sa}}', '{{cc-nd-nc}}',
'{{cc-nc}}', '{{cc-by-nc-2.0}}', '{{cc-by-nc-sa-2.0}}',
'{{cc-by-nd-nc-2.0}}', '{{cc-by-2.0-nc-nd}}', '{{cc-by-nc-nd-2.0}}',
'{{db-contact}}', '{{db-i2}}', '{{db-i1}}', '{{communityuseonly}}',
'{{db-disparage}}', '{{db-web}}', '{{db-userreq}}', '{{db-nouser}}',
'{{db-u3}}', '{{db-unfree}}'),
'fr': (u'{{suppression}}', u'{{à vérifier}}', u'{{ébauche}}'),
'ia': (u'{{Eliminar}}', u'{{Revision}}', u'{{Stub}}'),
'he': (u'{{מחק}}', u'{{פירושונים}}', u'{{הצבעת מחיקה}}'),
'nl': ('{{nuweg}}', '{{weg}}', '{{wb}}', '{{wiu}}', '{{nocat}}'),
'pl': ('{{ek}}', u'{{dopracować}}', '{{linki}}', u'{{źródła}}',
u'{{stub}}'),
'pt': ('{{wikificar}}', '{{reciclar}}', '{{lixo}}', u'{{revisão}}',
u'{{impróprio}}', u'{{apagar vaidade}}'),
'sv': (u'{{radera', u'{{Radera', u'{{städa}}', u'{{stub}}',
u'{{verifieras}}', u'{{språkvård}}', u'{{Källor', u'{{källor',
u'{{wikify}}', u'{{Ickewiki}}', u'{{ickewiki}}', u'{{Wikify}}'),
'zh': (u'{{VfD}}', u'{{AfD}}', u'{{unreferenced}}', u'{{db-reason}}',
u'{{cleanup}}', u'{{stub}}', u'{{uncategorized}}', u'{{notability}}',
u'{{copyedit}}', u'{{unreferenced}}', u'{{wikify}}',
u'{{Translating}}', u'{{copyvio}}', u'{{Notchinese}}'),
}
# TODO: merge 'done' with 'templates' above
class PageHandler:
# Initialization stuff
def __init__(self, page, date, length, loggedIn, user, comment):
self.page = page
self.date = date
self.length = length
self.loggedIn = loggedIn
self.user = user
self.comment = comment
# Display informations about an article
def showpageinfo(self):
pywikibot.output(u'[[%s]] %s ' % (self.page.title(), self.date))
print 'Length: %i bytes' % self.length
pywikibot.output(u'User : %s' % self.user)
def couldbebad(self):
return self.length < 250 or not self.loggedIn
def handlebadpage(self):
try:
self.content = self.page.get()
except pywikibot.IsRedirectPage:
pywikibot.output(u'Already redirected, skipping.')
return
except pywikibot.NoPage:
pywikibot.output(u'Already deleted')
return
for d in pywikibot.translate(pywikibot.getSite(), done):
if d in self.content:
pywikibot.output(
u'Found: "%s" in content, nothing necessary' % d)
return
print "---- Start content ----------------"
pywikibot.output(u"%s" % self.content)
print "---- End of content ---------------"
# Loop other user answer
answered = False
while not answered:
answer = pywikibot.input(question)
if answer == 'q':
sys.exit("Exiting")
if answer == 'd':
pywikibot.output(u'Trying to delete page [[%s]].'
% self.page.title())
self.page.delete()
return
if answer == 'e':
oldText = self.page.get()
text = oldText
editor = editarticle.TextEditor()
text = editor.edit(self.page.get())
if oldText != text:
pywikibot.showDiff(oldText, text)
msg = pywikibot.input(u'Summary message:')
self.page.put(text, msg)
return
if answer == 'b':
pywikibot.output(u'Blanking page [[%s]].' % self.page.title())
try:
self.page.put('',
comment=pywikibot.translate(
pywikibot.getSite(), blanking)
% self.content)
except EditConflict:
print "An edit conflict occured ! Automatically retrying"
handlebadpage(self)
return
if answer == '':
print 'Page correct ! Proceeding with next pages.'
return
# Check user input:
if answer[0] == 'u':
# Answer entered as an utf8 string
try:
choices = answer[1:].split(',')
except ValueError:
# User entered wrong value
pywikibot.error(u'"%s" is not valid' % answer)
continue
else:
try:
choices = answer.split(',')
except ValueError:
# User entered wrong value
pywikibot.error(u'"%s" is not valid' % answer)
continue
#test input
for choice in choices:
try:
x = int(choice)
except ValueError:
break
else:
answered = x in range(1, len(questionlist)+1)
if not answered:
pywikibot.error(u'"%s" is not valid' % answer)
continue
summary = u''
for choice in choices:
answer = int(choice)
# grab the template parameters
tpl = pywikibot.translate(pywikibot.getSite(),
templates)[questionlist[answer]]
if tpl['pos'] == 'top':
pywikibot.output(u'prepending %s...' % questionlist[answer])
self.content = questionlist[answer] + '\n' + self.content
elif tpl['pos'] == 'bottom':
pywikibot.output(u'appending %s...' % questionlist[answer])
self.content += '\n' + questionlist[answer]
else:
pywikibot.error(
u'"pos" should be "top" or "bottom" for template '
u'%s. Contact a developer.' % questionlist[answer])
sys.exit("Exiting")
summary += tpl['msg']+' '
pywikibot.output(u'Probably added %s' % questionlist[answer])
# pywikibot.output(newcontent) bug #2986247
self.page.put(self.content, comment=summary)
pywikibot.output(u'with comment %s\n' % summary)
def run(self):
self.showpageinfo()
if self.couldbebad():
print 'Integrity of page doubtful...'
try:
self.handlebadpage()
except pywikibot.NoPage:
print 'seems already gone'
print '----- Current time:', datetime.datetime.now()
class CleaningBot:
def __init__(self, site=None):
if site is None:
site = pywikibot.getSite()
self.site = site
def run(self):
for (page, date, length, loggedIn, username, comment) in \
self.site.newpages(100, repeat=True):
handler = PageHandler(page, date, length, loggedIn, username,
comment)
handler.run()
# Generate the question text
i = 0
questions = '\n'
questionlist = {}
for t in pywikibot.translate(pywikibot.getSite(), templates):
i += 1
questions += (u'%s) %s\n' % (i, t))
questionlist[i] = t
question = questions + question
# MAIN
if __name__ == "__main__":
try:
for arg in pywikibot.handleArgs():
pywikibot.warning(
u'argument "%s" not understood; ignoring.' % arg)
bot = CleaningBot()
bot.run()
except:
pywikibot.stopme()
raise