User:Lowercase sigmabot II/Source.py: Difference between revisions

Content deleted Content added
Updating source) (bot
Updating source) (bot
Line 1:
 
Source as of 0001:5433, 3 May 2012 (UTC).
 
== Sandbot1.py ==
Line 29:
import sys
import os
 
def shut_off_check(page="Coal ball"):
if api.getpage(page).lower() == "true":
return True
return False
 
def revision_user(page):
Line 45 ⟶ 40:
res = api.call(query)["query"]["pages"]
pageid = res.keys()[0]
for template in res[pageid]["templates"]:
# You didn't see this...
if not "templates" in yield res[pageid]:template
for x in xrange(21):
yield str(x)
else:
for template in res[pageid]["templates"]:
yield template["title"]
 
def heading_is_gone(box):
Line 64 ⟶ 54:
continue
elif heading_is_gone(sandbox):
api.prepend(sandbox, reinsert, summary="Reinserting sandbox header) (bot", minor=False, bot=True, force=True)
print sandbox, "{!s} had a sandbox headerheading reinserted.".format(sandbox)
 
user = "Lowercase sigmabot II"
Line 74 ⟶ 64:
api.set_all()
reinsert = "{{Sandbox heading}} <!-- Please leave this line alone! -->\n\n"
sandboxes = ("Wikipedia:Sandbox", "Wikipedia:Tutorial/Editing/sandbox", "Wikipedia:Tutorial/Formatting/sandbox", "Wikipedia:Tutorial/Wikipedia links/sandbox", "Wikipedia:Tutorial/Citing sources/sandbox", "Wikipedia:Tutorial/Keep in mind/sandbox")
 
templates = ("Template:Please leave this line alone (sandbox talk heading)", "Template:Please leave this line alone (Sandbox heading)", "Template:Sandbox heading/noedit", "Template:Please leave this line alone (sandbox talk heading)/noedit", "Template:Sandbox header (do not remove)", "Template:PLTLA (SH)", "Template:Please leave this line alone (sandbox heading)", "Template:Please leave this line alone (sandbox heading)/noedit")
sandboxes = ("Wikipedia:Sandbox", "Wikipedia:Tutorial/Editing/sandbox", "Wikipedia:Tutorial/Formatting/sandbox",
run()
"Wikipedia:Tutorial/Wikipedia links/sandbox", "Wikipedia:Tutorial/Citing sources/sandbox", "Wikipedia:Tutorial/Keep in mind/sandbox")
 
templates = ("Template:Please leave this line alone (sandbox talk heading)",
"Template:Please leave this line alone (Sandbox heading)",
"Template:Sandbox heading/noedit",
"Template:Please leave this line alone (sandbox talk heading)/noedit",
"Template:Sandbox header (do not remove)",
"Template:PLTLA (SH)",
"Template:Please leave this line alone (sandbox heading)",
"Template:Please leave this line alone (sandbox heading)/noedit")
 
if shut_off_check(page="User:Lowercase sigmabot II/Shutoff"):
run()
else:
print "Bot disabled."
api.logout()
sys.exit(0)
 
</source>
Line 124 ⟶ 99:
api.login(user, pw)
api.set_all()
reset_text = """{{Please leave this line alone (sandbox heading)}}<!--
{{Please leave this line alone (sandbox heading)}}<!--
* Welcome to the sandbox! *
* Please leave this part alone *
Line 133 ⟶ 107:
"""
 
threads_exist = 0
sandboxes = ("Wikipedia:Sandbox", "Wikipedia:Tutorial/Editing/sandbox", "Wikipedia:Tutorial/Formatting/sandbox", "Wikipedia:Tutorial/Wikipedia links/sandbox", "Wikipedia:Tutorial/Citing sources/sandbox", "Wikipedia:Tutorial/Keep in mind/sandbox")
 
def should_be_reset(box):
curtime = datetime.utcnow()
three_daysthree_min = timedelta(hoursseconds=72180)
query = api.querycall({"action":"query", "prop":"revisions", "titles":box, "rvprop":"timestamp"})["query"]["pages"]
pageid = query.keys()[0]
box_stamp = api.parse_date(query[pageid]["revisions"][0]["timestamp"])
if box_stamp < curtime - three_daysthree_min:
return True
return False
 
def revision_user(page):
query = {"action":"query", "prop":"revisions", "titles":page, "rvprop":"user"}
res = api.call(query)["query"]["pages"]
pageid = res.keys()[0]
return res[pageid]["revisions"][0]["user"]
 
def sandbox_wait(box):
Line 151 ⟶ 132:
break
# After it sleeps for 9 minutes without clearing the sandbox, it will be cleared regardless.
api.edit(box, reset_text, "Clearing sandbox) (bot", True, True, force=True)
return None
 
for sandbox in sandboxes:
if should_be_resetrevision_user(sandbox) == "Lowercase sigmabot II":
return Truecontinue
api.edit(sandbox, reset_text, "Clearing sandbox) (bot", True, True)
elif should_be_reset(sandbox):
api.edit(sandbox, reset_text, "Clearing sandbox) (bot", True, True, force=True)
else:
threads_exist = 1
Thread(target=sandbox_wait, args=(sandbox)).start()
 
if threads_exist == 1:
api.logout()
print "BotThreads disabled.exist"
else:
api.logout()
</source>