STOP_PAGE='http://en.wikipedia.org/w/index.php?title=User:DASHBot/patrol&action=raw' #The url for the bot's stop page. from urllib2 import urlopen print 'Checking stop page...' if 'PATROL NEW PAGES UP FOR DELETION = YES' not in urlopen(STOP_PAGE).read():quit("Ive been haulted") del urlopen from MySQLdb import connect from time import time db = connect(db='enwiki_p', host="enwiki-p.rrdb.toolserver.org", read_default_file="~/.my.cnf") del connect from wikipedia import getSite site = getSite() site.forceLogin() r=[] print 'Querying for pages that can be patrolled...' t=time() #below is the database query. The deletion categories are "IN ('Candiates_for..." db.query(""" SELECT rc_title,rc_id from recentchanges JOIN page on page_title=rc_title and page_namespace=0 JOIN categorylinks on cl_from=page_id and cl_to IN ('Candidates_for_speedy_deletion','Articles_for_deletion','All_articles_proposed_for_deletion') WHERE rc_new=1 and rc_namespace=0 and rc_patrolled=0;""") for p in db.use_result().fetch_row(0): r.append((p[0],p[1])) for title,rcid in r: print 'Patrolling: ',title site.patrol(rcid) print 'Sucess!'