importpywikibot,re,roman,timefrompywikibotimportpagegeneratorsfrompywikibot.botimportExistingPageBot## wikicosassite=pywikibot.Site('es','wiktionary')classMyBot(ExistingPageBot):deftreat_page(self):"""Load the given page, do some changes, and save it."""title=self.current_page.title()text=self.current_page.text##TEMPLATE = r'\{\{(?:forma sustantivo plural|f.s.p.|plural)(?:\|leng=es)?\|(.*?)(?:\|leng=es)?}}' ##TEMPLATE2 = r'\{\{(?:forma sustantivo)(?:\|leng=es)?\|(.*?)(?:\|leng=es)?\|plural(?:\|leng=es)?}}'TEMPLATE=r'\{\{(?:forma adjetivo)(?:\|\w+=\w+)*\|([^}\|=]*?)(?:\|\w+=\w+)*}}'TEMPLATE2=r'\{\{(?:f.adj2|forma adjetivo 2)\|([^}\|=]*).*?}}'PATTERN=r'(?:'+TEMPLATE+r'|'+TEMPLATE2+r')'mash=re.search(PATTERN,text)word=mashandmash.group(1)ifwordandnotpywikibot.Page(site,mash.group(1)).exists():withopen('LIST','a')asf:f.write('*[['+word+']] ([['+title+']])\n')defmain(*args:str):"""Parse command line arguments and invoke bot."""options={}gen_factory=pagegenerators.GeneratorFactory()# Option parsinglocal_args=pywikibot.handle_args(args)# global optionslocal_args=gen_factory.handle_args(local_args)# generators optionsforarginlocal_args:opt,sep,value=arg.partition(':')ifoptin('-summary','-text'):options[opt[1:]]=valueMyBot(generator=gen_factory.getCombinedGenerator(),**options).run()if__name__=='__main__':main()