Content deleted Content added
Updating source) (bot |
Updating source) (bot |
||
Line 1:
Source as of
== Sandbot1.py ==
Line 29:
import sys
import os
return True▼
def revision_user(page):
Line 45 ⟶ 40:
res = api.call(query)["query"]["pages"]
pageid = res.keys()[0]
else:▼
▲ for template in res[pageid]["templates"]:
def heading_is_gone(box):
Line 64 ⟶ 54:
continue
elif heading_is_gone(sandbox):
api.prepend(sandbox, reinsert, summary="Reinserting sandbox header
print 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")
▲"Wikipedia:Tutorial/Wikipedia links/sandbox", "Wikipedia:Tutorial/Citing sources/sandbox", "Wikipedia:Tutorial/Keep in mind/sandbox")
▲ run()
print "Bot disabled."▼
api.logout()
</source>
Line 124 ⟶ 99:
api.login(user, pw)
api.set_all()
reset_text = """{{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()
query = api.
pageid = query.keys()[0]
box_stamp = api.parse_date(query[pageid]["revisions"][0]["timestamp"])
if box_stamp < curtime -
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
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= if threads_exist == 1:
api.logout()▼
▲ api.logout()
</source>
|