User:John Bot IV/Source
Appearance
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Reame: TODO
"""
#
# (C) CWii, BJWeeks and Betacommand, 2008
#
# Distributed under the terms of the MIT license.
#
__version__ = '$Id: $'
#
import wikipedia, pagegenerators, catlib
import re
import JohnBots
class NFCCBot (JohnBots.JohnBot):
def main(self):
cat = catlib.Category(self.site, 'Category:All non-free media')
gen = pagegenerators.CategorizedPageGenerator(cat, True)
for image in gen:
if image.namespace() == 6 and image.exists() and not image.isRedirectPage():
useCount = 0
img = wikipedia.ImagePage(self.site, image.title())
wikipedia.output("Processing %s" % img.title())
uses = img.usingPages()
for arti in uses:
if arti.namespace() == 0:
##It's okay
wikipedia.output('%s is used on %s' % (img.title(),arti.title()))
useCount += 1
elif arti.namespace()== 10:
continue
else:
#OMG BAD USE
wikipedia.output('!BAD: %s is used on %s' % (img.title(),arti.title()))
pText = arti.get()
pText = re.sub('(?: |_)'.join(re.escape(img.titleWithoutNamespace()).split('\\ ')),
'NonFreeImageRemoved.svg', pText, re.I)
#arti.put(pText, 'Removing Non-Free Image per NFCC')
if useCount == 0:
wikipedia.output('%s is not used!!' % img.title())
if re.search(r'{{\s*di-orphaned(?: |_)fair(?: |_)use\s*\|.*}}',
img.get(), re.IGNORECASE):
wikipedia.output("Already tagged.")
continue
else:
##user = img.getLatestUploader()
uploaders = img.getFileVersionHistory()
#Leave a message first
for uploader in uploaders:
wikipedia.output(u'Leaving message for: %s' % uploader[1])
self.leave_message(uploader[1], "\n{{subst:User:John Bot IV/Messages/NFCC7}} ~~~~",
"[[User:John Bot IV]], [[%s]] is going to be deleted" % img.title(), force = True)
img.put('%s\n%s' % ('{{subst:orfud}}', img.get()), '[[User:John Bot IV|John Bot IV]],')
if __name__ == "__main__":
try:
bot = NFCCBot('John Bot IV')
bot.main()
finally:
wikipedia.stopme()