Content deleted Content added
Updating source) (bot |
m Replaced deprecated <source> tags with <syntaxhighlight> |
||
(6 intermediate revisions by 5 users not shown) | |||
Line 1:
Source as of
== Sandbot1.py ==
Line 17:
If the template is present, it does nothing.
<
#!/home/sigma/.local/bin/python3
# -*- coding: utf-8 -*-
Line 27:
import ceterach
import mwparserfromhell as mwparser
Line 35:
def main():
global api
api = ceterach.api.MediaWiki("
api.login("Lowercase sigmabot II", passwords.lcsb2)
api.set_token("edit")
Line 67:
def check_if_heading_is_gone(self, box):
tl = self.api.iterator(500, prop="templates", tlnamespace=10, tllimit=500, titles=box.title)
res = {x['title'] for x in next(tl).get("templates", "")}
return not res & self.TEMPLATES
Line 85:
main()
</syntaxhighlight>
== Sandbot2.py ==
Line 98:
■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■--></pre>
<
#!/home/sigma/.local/bin/python3
# -*- coding: utf-8 -*-
# LGPLv2+ license, look it up
import datetime▼
import time
import os
import sys
import threading
import arrow
import ceterach
reset_text = "{{subst:Sandbox reset}}"
tpl_reset_text = "{{subst:Template sandbox reset}}"
def main():
global api
api = ceterach.api.MediaWiki("
with open("opener.pkl", 'rb') as fp:
api.
bot = SandBot2(api)
bot.run()
class SandBot2:
SANDBOXES = ("Wikipedia:Sandbox",
Line 136 ⟶ 133:
"Wikipedia:Tutorial/Keep in mind/sandbox"
)
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 talk:Sandbox",
"Wikipedia talk:Tutorial/Editing/sandbox",
"Wikipedia talk:Tutorial/Formatting/sandbox",
"Wikipedia talk:Tutorial/Wikipedia links/sandbox",
"Wikipedia talk:Tutorial/Citing sources/sandbox",
"Wikipedia talk:Tutorial/Keep in mind/sandbox",
"User:Sandbox",
"Template:Template sandbox",
}
def __init__(self, api, shutoff="User:Lowercase sigmabot II/Shutoff"):
self.api = api
self.shutoff_page = api.page(shutoff)
@property
def is_allowed(self):
return self.shutoff_page.content.lower() == "true"
def wait(self, box):
for __ in range(3):
Line 155 ⟶ 167:
# will clear the box regardless.
print("Done with sleeping, clearing {!r}".format(box.title))
self.api.login("Lowercase sigmabot II",
self.api.set_token("edit")
text = tpl_reset_text if box.namespace == 10 else reset_text
def parse_date(self, date):
return
def box_needs_reset(self, box):
now =
three_min =
# there's probably a way to use MediaWiki.iterator(), but too lazy
res = self.api.call(action="query", prop="revisions", titles=box.title, rvprop="timestamp", limit="2")
Line 172 ⟶ 185:
return True
return False
def run(self):
if not self.is_allowed:
Line 184 ⟶ 197:
if self.box_needs_reset(box):
print("Clearing {!r}".format(sandbox))
print(
else:
# The bot will fork, and continue on to the next sandbox
Line 192 ⟶ 205:
# os._exit(0) # Exit the child process
threading.Thread(target=self.wait, args=(box,)).start()
if __name__ == "__main__":
main()
</syntaxhighlight>
|