def test_otd(self): self.assertEqual( process(""" {{article history |action1=GAN |action1date=12:52, 7 December 2005 |action1result=listed |action1oldid=30462537 |currentstatus=GA |topic=math }} {{On this day|date1=2004-05-28|oldid1=6717950|date2=2005-05-28|oldid2=16335227}}""" ), """ {{article history |action1=GAN |action1date=12:52, 7 December 2005 |action1link= |action1result=listed |action1oldid=30462537 |currentstatus=GA |otddate=2004-05-28 |otdoldid=6717950 |otd2date=2005-05-28 |otd2oldid=16335227 |topic=math }}""")
def test_blank_ah(self): self.assertEqual(process(""" {{Article history}} {{ITN talk|date1=1 June 2009}}"""), """ {{article history |itndate=1 June 2009 }}""")
def test_otd(self): self.assertEqual(process(""" {{article history |action1=GAN |action1date=12:52, 7 December 2005 |action1result=listed |action1oldid=30462537 |currentstatus=GA |topic=math }} {{On this day|date1=2004-05-28|oldid1=6717950|date2=2005-05-28|oldid2=16335227}}"""), """ {{article history |action1=GAN |action1date=12:52, 7 December 2005 |action1link= |action1result=listed |action1oldid=30462537 |currentstatus=GA |otddate=2004-05-28 |otdoldid=6717950 |otd2date=2005-05-28 |otd2oldid=16335227 |topic=math }}""")
def test_blank_ah(self): self.assertEqual( process(""" {{Article history}} {{ITN talk|date1=1 June 2009}}"""), """ {{article history |itndate=1 June 2009 }}""")
def test_already(self): self.assertEqual(process(""" {{Article history|itndate=1 June 2009}} {{ITN talk|date1=1 June 2010}}"""), """ {{article history |itndate=1 June 2009 |itn2date=1 June 2010 }}""")
def test_already(self): self.assertEqual( process(""" {{Article history|itndate=1 June 2009}} {{ITN talk|date1=1 June 2010}}"""), """ {{article history |itndate=1 June 2009 |itn2date=1 June 2010 }}""")
def test_dyk(self): self.assertEqual(process(""" {{Article history | action1 = GAN | action1date = 14:45, 22 March 2015 (UTC) | action1link = Talk:Dyslexia/GA1 | action1result = Passed | action1oldid = 653061069 }} {{dyktalk|6 April|2015|entry= ... that '''[[dyslexia]]''' is the most common learning disability, affecting about 3% to 7% of people?}}"""), """ {{article history |action1=GAN |action1date=14:45, 22 March 2015 (UTC) |action1link=Talk:Dyslexia/GA1 |action1result=Passed |action1oldid=653061069 |dykdate=6 April 2015 |dykentry= ... that '''[[dyslexia]]''' is the most common learning disability, affecting about 3% to 7% of people? }}""")
def test_dyk(self): self.assertEqual( process(""" {{Article history | action1 = GAN | action1date = 14:45, 22 March 2015 (UTC) | action1link = Talk:Dyslexia/GA1 | action1result = Passed | action1oldid = 653061069 }} {{dyktalk|6 April|2015|entry= ... that '''[[dyslexia]]''' is the most common learning disability, affecting about 3% to 7% of people?}}""" ), """ {{article history |action1=GAN |action1date=14:45, 22 March 2015 (UTC) |action1link=Talk:Dyslexia/GA1 |action1result=Passed |action1oldid=653061069 |dykdate=6 April 2015 |dykentry= ... that '''[[dyslexia]]''' is the most common learning disability, affecting about 3% to 7% of people? }}""")
def test_itn(self): self.assertEqual(process(""" {{article history |action1=GAN |action1date=12:52, 7 December 2005 |action1result=listed |action1oldid=30462537 |currentstatus=GA |topic=math }} {{ITN talk|date1=12 September 2009|date2=24 December 2013}}"""), """ {{article history |action1=GAN |action1date=12:52, 7 December 2005 |action1link= |action1result=listed |action1oldid=30462537 |currentstatus=GA |itndate=12 September 2009 |itn2date=24 December 2013 |topic=math }}""")
def test_itn(self): self.assertEqual( process(""" {{article history |action1=GAN |action1date=12:52, 7 December 2005 |action1result=listed |action1oldid=30462537 |currentstatus=GA |topic=math }} {{ITN talk|date1=12 September 2009|date2=24 December 2013}}"""), """ {{article history |action1=GAN |action1date=12:52, 7 December 2005 |action1link= |action1result=listed |action1oldid=30462537 |currentstatus=GA |itndate=12 September 2009 |itn2date=24 December 2013 |topic=math }}""")
def test_empty(self): self.assertEqual(process(""), "")
# Set up refs gen article_history = pywikibot.Page(site, "Template:Article history") references_args = {"onlyTemplateInclusion": True, "namespaces": (1), "content": True} references_gen = article_history.getReferences(**references_args) lower = unicode.lower def has_redundant_templates(page): """Checks if the page should be fixed by this bot.""" text = lower(page.text) text = text[:text.find("==")] return any("{{" + template in text for template in REDUNDANT_TEMPLATES) if args.count: num_edits = args.count print_log("Starting off with %d edits made." % num_edits) else: num_edits = 0 for page in references_gen: if has_redundant_templates(page): print("About to process %s." % page.title(withNamespace=True).encode("utf-8")) page.text = process(page.text) if not args.interactive or prompt.yn("Save %s?" % page.title(withNamespace=True).encode("utf-8")): page.save(summary=SUMMARY) num_edits += 1 print_log("%d edits made so far." % num_edits) if args.limit and num_edits >= args.limit: print_log("%d edits (limit) reached; done." % num_edits) sys.exit(0) elif prompt.yn("Exit?"): sys.exit(0)
lower = unicode.lower def has_redundant_templates(page): """Checks if the page should be fixed by this bot.""" text = lower(page.text) text = text[:text.find("==")] return any("{{" + template in text for template in REDUNDANT_TEMPLATES) if args.count: num_edits = args.count print_log("Starting off with %d edits made." % num_edits) else: num_edits = 0 for page in references_gen: if has_redundant_templates(page): print("About to process %s." % page.title(withNamespace=True).encode("utf-8")) page.text = process(page.text) if not args.interactive or prompt.yn( "Save %s?" % page.title(withNamespace=True).encode("utf-8")): page.save(summary=SUMMARY) num_edits += 1 print_log("%d edits made so far." % num_edits) if args.limit and num_edits >= args.limit: print_log("%d edits (limit) reached; done." % num_edits) sys.exit(0) elif prompt.yn("Exit?"): sys.exit(0)