User:Sz-iwbot/code

#!/usr/bin/python
# -*- coding: utf-8  -*-
"""
check gallery in commons. tag gallery with no media/files {{speedydelete}}.
 
"""
#
# (C) Shizhao, 2008
#
# Distributed under the terms of the MIT license.
#
__version__ = '$Id: checkcommons.py,v beta 2008-03-26 Shizhao $'
import os
import sys,time
import wikipedia, config
n=0
sd=u'{{speedydelete|gallery with no media/files}}--~~~~\n'
template=u'speedydelete'
testlist=[]
plist=[]
site=wikipedia.getSite()
def speedydelete(page):
 
    if 'Copyvio' not in page.templates() and not page.isRedirectPage():
#            print '%s is RedirectPage, PASS. ' % page:
        if page.isEmpty():
            text = page.get()
            text=u'{{speedydelete|Empty}}--~~~~\n'+text
            page.put(text, u"Bot: is Empty. Flag speedydelete tag")
            print '%s is Empty, Flag speed delete tag.' % page
        elif page.isDisambig():
 
            print '%s is Disambig, PASS. ' % page
 
        elif 'Speedydelete' in page.templates():
            print '%s have tag speedydelete tag. ' % page
        elif len(page.imagelinks(loose=True))==0:
            text = page.get()
            text=sd+text
            page.put(text, u'Bot flag speedydelete tag: gallery with no media/files')
#            title=page.title()
#            title='*[['+title+']]\n'
#            testlist.append(title)
#            plist.append(page)
            print '%s Flag speedydelete' % page
    else:
        print '%s is Copyvio!' % page
 
for (page, date, length, loggedIn, username, comment) in site.newpages(50, repeat = True):
    try:
        if page.namespace()==0:
            speedydelete(page)
        time.sleep(5*60) 
    except:
        raise
#    else:
#        print '%s is OK: %s words' % (page, length)
#test=wikipedia.Page(site, u'User:Sz-iwbot/sd')
#testlists=''.join(testlist)
#test.put(testlists,'sdlist')
#print plist
Last modified on 1 April 2008, at 15:08