User:SD5bot/userfy.py
Appearance
#!/usr/bin/python
#
# (C) 2012 Legoktm and SD5, under the MIT License
# Checks the new pages list to see whether it should have been made in the userspace, and if so, moves it.
#
import datetime, re, sys, time
from wikipedia import *
import catlib, pagegenerators
from add_text import add_text
site = getSite()
def main():
gen = pagegenerators.NewpagesPageGenerator(number = 150)
for page in gen:
try:
UnicodeToAsciiHtml(page.title())
if not '/' in page.title(): continue
creator = page.getVersionHistory(reverseOrder = True, revCount = 1)[0][2]
time.sleep(1)
if page.title().startswith(creator + '/'):
# move page
old = page.title()
new = 'User:' + page.title()
page.move(new, reason='BOT: Moving accidentally created subpage into userspace')
# request deletion of old page if not a bot account
oldpage = Page(site, old)
oldpage.put('{{db-r2}}', 'BOT: Nominating moved page for deletion ([[WP:CSD#R2|CSD R2]])')
#Leave a talk-page notice
talk_page = Page(site, 'User talk:' + creator)
talk_page_notice = '{{subst:User:SD5bot/templates/userfy|1=%s|2=%s}} ~~~~' %(old, new)
add_text(page = talk_page, addText = '\n' + talk_page_notice, summary = 'BOT: moved [[%s]] to [[%s]]' %(old, new), always = True, create = True)
else:
continue
except:
continue
if __name__ == "__main__":
try:
main()
finally:
stopme()