def glob(): lre.pats["entry"] = lre.lre(ur"(?sm)\{\{\s*แจ้งปรับปรุงหน้าอัตโนมัติ\s*" ur"((?:\{\{.*?\}\}|.)*?)\s*\}\}") lre.pats["param"] = lre.lre(r"(?s)\|\s*((?:\{\{.*?\}\}|.)*?)\s*(?=\|)") lre.pats["num"] = lre.lre(r"\d+$") lre.pats["user0"] = lre.lre(r"\{\{User0\|(.*?)\}\}") lre.pats["trimComment"] = lre.lre(r"<!--#(.*?)#-->")
def glob(): global paten, patWOen, patlink, patoldlink, dummytext, patLI prepat = r"(?m)^[\*\#]+\s*\[\[(?!:en:)(.*?)(?:\|.*?)?\]\]" sufpat = r".*?\[\[(:en:.*?)\]\]" patoldlink = lre.lre(r"(?m)(^--> \[\[.*?\]\] <!--\n)+") patlink = lre.lre(r"(?m)(?<=^--> )\[\[.*\]\](?= <!--$)") patWOen = lre.lre(prepat) paten = lre.lre(prepat + sufpat) dummytext = "<!-- dummy for putting -->"
def dorender(self): if self.tabactive == 'page': self.content = self.page.get() self.pat_before = '~~~#m!' self.pat_after = self.pat_before[::-1] self.pat = self.pat_before + r'\d+' + self.pat_after self.begin_assert = '((?:(?!~~~).)*?)' self.begin = '~~~#h!' self.begin = self.begin + self.begin_assert + self.begin[::-1] self.end = '~~~#e!' self.leadlink = lre.lre(r'^[\[\{]+') self.traillink = lre.lre(r'[#{].*$') self.cnt = 0 self.text = [] ptr = 0 while ptr < len(self.content): if self.content[ptr:ptr + 2] == '{{' or self.content[ptr:ptr + 2] == '[[': self.text.append(self.content[ptr]) self.text.append(self.pat_before) self.text.append(str(self.cnt)) self.cnt += 1 self.text.append(self.pat_after) self.text.append(self.content[ptr + 1]) ptr += 2 else: self.text.append(self.content[ptr]) ptr += 1 self.text = ''.join(self.text) self.content = self.text self.rmtag('pre') self.rmtag('nowiki') self.rmtag('source') self.content = lre.sub('(?s)<!--.*?-->', '', self.content) matches = list( lre.finditer('(?s)(' + self.pat + r')(.*?)(?=[|}\]\n])', self.content)) links = [] for match in matches: links.append(match.group(2)) translatedLinks = self.translate(links) for i, match in enumerate(matches): self.text = self.text.replace(match.group(), translatedLinks[i], 1) self.finalize()
def mosteditsArt(): """ most edits """ regexArt = lre.genData(conf.tagind, u"บทความแก้ไขมากสุด") regexArtlist = lre.genData(conf.tagind, u"บทความรายชื่อแก้ไขมากสุด") oldtable = getdat(regexArt) oldtablelist = getdat(regexArtlist) table = [] tablelist = [] ptr = 0 patListName = lre.lre(lre.sep(conf.listname)) for page, revisions in site.mostrevisionspages(): if len(tablelist) < 5 and patListName.search(page.title()): tablelist.append([page.title(), getrankold(page.title(), oldtablelist), revisions, firstContributor(page)]) elif len(table) < 10 and not patListName.search(page.title()): table.append([page.title(), getrankold(page.title(), oldtable), revisions, firstContributor(page)]) elif (len(tablelist) >= 5) and (len(table) >= 10): break writetable(table, regexArt) writetable(tablelist, regexArtlist)
def dorender(self): if self.tabactive == 'page': self.content = self.page.get() self.pat_before = '~~~#m!' self.pat_after = self.pat_before[::-1] self.pat = self.pat_before + r'\d+' + self.pat_after self.begin_assert = '((?:(?!~~~).)*?)' self.begin = '~~~#h!' self.begin = self.begin + self.begin_assert + self.begin[::-1] self.end = '~~~#e!' self.leadlink = lre.lre(r'^[\[\{]+') self.traillink = lre.lre(r'[#{].*$') self.cnt = 0 self.text = [] ptr = 0 while ptr < len(self.content): if self.content[ptr:ptr+2] == '{{' or self.content[ptr:ptr+2] == '[[': self.text.append(self.content[ptr]) self.text.append(self.pat_before) self.text.append(str(self.cnt)) self.cnt += 1 self.text.append(self.pat_after) self.text.append(self.content[ptr + 1]) ptr += 2 else: self.text.append(self.content[ptr]) ptr += 1 self.text = ''.join(self.text) self.content = self.text self.rmtag('pre') self.rmtag('nowiki') self.rmtag('source') self.content = lre.sub('(?s)<!--.*?-->', '', self.content) matches = list(lre.finditer('(?s)(' + self.pat + r')(.*?)(?=[|}\]\n])', self.content)) links = [] for match in matches: links.append(match.group(2)) translatedLinks = self.translate(links) for i, match in enumerate(matches): self.text = self.text.replace(match.group(), translatedLinks[i], 1) self.finalize()
def glob(): global datenow, template template = wp.Page(conf.templateName) lre.pats["tl"] = lre.lre(ur"(?i)\{\{\s*%s\s*\}\}\s*" % lre.sep([page.title(withNamespace=False) for page in list(template.backlinks(filterRedirects=True)) + [template]])) datenow = site.getcurrenttime()
def glob(): patintclass = lre.lre(ur"(?ms)\|\s*title\s*=(.*?)$") delimit = [ur"\s*[\•\·]\s*", ur"\ +[\•\.\·\-] +", ur"\ *\{\{(?:[\,\•·]|[\•\·\!]w|·wrap|จุด)\}\}\s*", ur"\s*\&\#124\;\s*"] delimit = lre.sep(delimit) + ur"(?!(?:(?![\[\]]).)*\])" patdel = lre.lre(u"(?s)(\|\ *list\d+(?:(?!below|seealso|" + #u"(?<=\]\])" + delimit + u").)*)" + #u"(?<=\]\])" + delimit) patnl = lre.lre(u"(list\d+)\s*=\s*(?![\|\s\}])") patwrap = lre.lre(u"\{\{[Nn]owrap\s*(?:\|(.*?))?\}\}\ *") patrmwrap = lre.lre(u"\{\{[Nn]owrap.*?\}\}\ *") triml = lre.lre(u"\n+") patbr = lre.lre(u"(?m)^(\*[^\n]*)<\s*/?\s*br\s*/?\s*>") alltag = [u"small", u"span", u"div"] patopen = lre.lre(u"(?m)^\*\ *(<" + lre.sep(alltag) + u">)\s*\[\[") patclose = lre.lre(u"\]\]\ *(</" + lre.sep(alltag) + u">)")
def glob(): lre.pats["subtl"] = lre.lre("\{\{\{(.*?)\}\}\}")
def glob(): lre.pats["trimComment"] = lre.lre(r"<!--#(.*?)#-->")
def glob(): global patclear patclear = lre.lre(ur"(?ms)^(\!.*?$\n).*?(^\|\})")
def glob(): global dummytext dummytext = "<!-- dummy -->" lre.pats["maintaincat"] = lre.lre("(?i)article|stub|wikipedia|without") lre.pats["name"] = lre.lre(r"\[\[:(.*?)\]\]") lre.pats["dummy"] = lre.lre(dummytext + r"\s*")
def glob(): lre.pats["site_APISite_li"] = lre.lre("(?<=<li>).*?(?=</li>)")
def glob(): lre.pats["stripcomment"] = lre.lre(u"(?s):?\s*เนื้อหาเดิม.*") lre.pats["ref"] = lre.lre(u"(?ms)^== *อ้างอิง *==.*")
def glob(): lre.pats["name"] = lre.lre(r"\[\[:.*?:(.*?)\]\]") # strip namespace in order to i18n properly lre.pats["endtable"] = lre.lre(ur"(?m)^\|\}")
def glob(): global pageMain, contentMain pageMain = None contentMain = None lre.pats["tspan"] = lre.lre("<.*?>")
def glob(): lre.pats["rmdisam"] = lre.lre(ur"\s+\([^\(]*?\)\s*$") lre.pats["thai"] = lre.lre(u"[\u0e00-\u0e7f]") lre.pats["exc"] = lre.lre("(?m)^\* *\[\[ *(.*?) *\]\] *$")