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

Content deleted Content added
Updating source) (bot
Updating source) (bot
Line 1:
 
Source as of 00:4552, 23 May 2012 (UTC).
 
== Sandbot1.py ==
Line 113:
from wikibot import WikiBot
from datetime import datetime, timedelta
from threading import timeThread
import sys
import os
Line 123:
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 131 ⟶ 132:
"""
 
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")
"Wikipedia:Tutorial/Wikipedia links/sandbox", "Wikipedia:Tutorial/Citing sources/sandbox", "Wikipedia:Tutorial/Keep in mind/sandbox")
pid = "r"
 
def shut_off_check(page="Coal ball"):
if api.getpage(page).lower() == "true":
return True
return False
 
def should_be_reset(box):
curtime = datetime.utcnow()
three_minthree_days = timedelta(secondshours=18072)
query = api.callquery({"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_minthree_days:
return True
return False
 
def sandbox_wait(box):
if shut_off_check("User:Lowercase sigmabot II/Shutoff") is False:
api.logoutfor blah in xrange(3):
sys time.exitsleep(060*3)
if should_be_reset(sandboxbox):
break
# After it sleeps for 9 minutes without clearing the sandbox, it will be cleared regardless.
api.edit(sandboxbox, reset_text, "Clearing sandbox) (bot", True, True)
return TrueNone
 
for sandbox in sandboxes:
Line 158 ⟶ 157:
api.edit(sandbox, reset_text, "Clearing sandbox) (bot", True, True)
else:
Thread(target=sandbox_wait, args=(sandbox)).start()
pid = os.fork() # You didn't see this....
if pid == 0:
for blah in xrange(3):
if should_be_reset(sandbox):
api.edit(sandbox, reset_text, "Clearing sandbox", True, True)
break
else:
time.sleep(60*3)
# After it sleeps for 9 minutes without clearing the sandbox, it will be cleared regardless.
api.edit(sandbox, reset_text, "Clearing sandbox", True, True)
os._exit(0) # Exit the child process (I think)
 
if pid == "r": # this will be True if the bot did not os.fork()
api.logout()
 
api.logout()
</source>