Utilisateur:ZaranBot
La bibliothèque libre.
Bot géré par Zaran. Encore un phase de dressage (je commence à regarder les possibilités offertes par pywikipediabot). A priori, j’envisage pour ce bot des actions ponctuelles pour des manipulations à l’échelle d'un livre, telle que le renommage des pages, ou l’import d'un livre présent sur un autre site. Je demanderai le statut de bot quand j’aurai fini mon dressage.
#!/usr/bin/python # -*- coding: utf-8 -*- """ Script to transclude pages into main namespace. Read """ import wikipedia as pywikibot import pagegenerators class TranscludeBot : msg = { 'fr' : u'Bot : transclusion', } def __init__(self,title,index,site,lastPage,cats,references,test) : self.site = pywikibot.getSite() self.msg = pywikibot.translate(self.site, self.msg) self.gen = pagegenerators.LinkedPageGenerator(pywikibot.Page(self.site,title)) self.lastPage = lastPage self.cats = cats self.index = index self.references = references self.test = test def run(self) : pageListWithNumbers=[] previous = None for page in self.gen : if page.namespace()== 104 : number = int((page.title().rpartition('/'))[2]) if previous <> None : current.append(number) previous.append(number-1) pageListWithNumbers.append(previous) previous=current else : previous=current current.append(number) else : current = [page] current.append(self.lastPage) pageListWithNumbers.append(current) for item in pageListWithNumbers : text = u"<pages header=1 index=\"{0}\" from={1} to={2}>".format(self.index,item[1],item[2]) if self.references : text+= '\n<references/>' if self.cats : text+='\n' for cat in self.cats : text+= u"\n[[Catégorie:{0}]]".format(cat) if self.test : pywikibot.output(u'=======================================\n'+ item[0].title()+'\n'+ u'---------------------------------------\n'+ text) else : page = item[0] page.put(text,self.msg,minorEdit=False) def main(): ''' Parse command line, instantiate the bot and run it ''' site = pywikibot.getSite() catList= [] test = False references = False for arg in pywikibot.handleArgs(): if arg.startswith('-title') : title = arg[7:] if not title : pywikibot.output("You must provide a page with links") return False if not pywikibot.Page(site,title).exists() : pywikibot.output("The title page you provided doesn't exist") return False elif arg.startswith('-index') : index= arg[7:] if not index : pywikibot.output("You must provide a index name") return False if not pywikibot.Page(site,'Livre:'+index).exists() : pywikibot.output("The index you provided doesn't exist") return False elif arg.startswith('-last') : last= int(arg[6:]) if not last : pywikibot.output('You must provide a last page') return False elif arg.startswith('-cats') : cats = arg[6:] catList = cats.split(':') elif arg.startswith('-test') : test = True elif arg.startswith('-references') : references = True bot = TranscludeBot(title,index,site,last,catList,references,test) bot.run() if __name__ == "__main__": try: main() finally: pywikibot.stopme()