User:Inductiveload/Scripts/Page shifter

From Wikisource
Jump to: navigation, search
#!/usr/bin/env python
 
#Complain to User:Inductiveload
 
 
import pw_script_header
import wikipedia
 
 
class PageShifter():
 
    def __init__(self):
 
        self.start_page = 5
        self.end_page = 14
 
        self.offset = -1 #the offset to add to each page
 
 
        #forwards iteration, useful when shifting pages to lower numbers
        pagelist = range(self.start_page, self.end_page+1)
 
        #reverse iteration, useful when shifting pages to higher numbers
        #pagelist = reversed(range(self.start_page, self.end_page+1))
 
        #or a set of page numbers that you choose, useful for 
        #pagelist = [1,2,3,4,5,6,7,8,9,10,11,100,101,102,103,104,105,361,362,363,364]
 
        leave_redirects  = False #don't leave redirects if you will move a page over where this one was
        replace_redirects = False #replace redirects with dated soft redirects
 
        self.old_index = ur'Historical Record of the Fifty-Sixth, Or the West Essex Regiment of Foot.djvu'
 
        self.new_index = self.old_index
        #self.new_index = ur'Sacred Books of the East - Volume 8.djvu'
 
        self.summary = ur'Realign pages to new DjVu.'
        #self.summary = ur'Move pages to new DjVu index.'
 
        self.site = wikipedia.getSite('en', 'wikisource')
 
        for old_page_no in pagelist:
 
            print "(INF)Processing page %d" % old_page_no
 
            new_page_no = old_page_no + self.offset
 
            old_page_title = 'Page:%s/%d' % (self.old_index, old_page_no)
            new_page_title = 'Page:%s/%d' % (self.new_index, new_page_no)
 
            old_page = wikipedia.Page(self.site, old_page_title)
            new_page = wikipedia.Page(self.site, new_page_title)
 
            print '\t(INF)Moving page %s to page %s' % (old_page_title, new_page_title)
 
            old_page.move(new_page_title, reason=self.summary, movetalkpage=True, throttle=True, leaveRedirect=leave_redirects)
 
            if replace_redirects:
                print '\t(INF)Placing dated soft redirect at %s' % (old_page_title)
 
                old_page.put('{{subst:dated soft redirect|[[%s]]}}' % new_page_title,
                                comment='Replacing redirect with dated soft redirect')
 
 
if __name__ == "__main__":
    ps = PageShifter()