def article(self): try: return self._article except AttributeError: try: article = self.checker.cache[self.article_name] except KeyError: self._article = None else: self._article = wikiparse.wikiparse(article) return self._article
def main(): for move in session.query(tables.Move): wiki.mark_needed_pages([move.name + ' (move)']) wiki.mark_needed_pages([move.name]) for ability in session.query(tables.Ability): wiki.mark_needed_pages([ability.name + ' (ability)']) wiki.mark_needed_pages([ability.name]) for item in session.query(tables.Item): wiki.mark_needed_pages([item.name + ' (item)']) wiki.mark_needed_pages([item.name]) with open('diffs.cat', 'w') as catfile, open('diffs.wiki', 'w') as wikifile: try: catfile_fileno = catfile.fileno() os.fchmod(catfile_fileno, os.fstat(catfile_fileno).st_mode | stat.S_IEXEC) catfile.write('#! /bin/cat\n\n') except Exception: print "Warning: couldn't make output file executable" wikifile.write(dedent(""" This __NOTOC__ page shows '''some''' differences between {veekun} and the {powiki}. (It also shows bugs in the script that made the page.) Generated by pokemwdb/powiki.py from https://github.com/encukou/pokemwdb. Wanna use this page? * Check if the difference is still there – this page doesn't get updated often. * If the wiki is obviously more wrong, improve it. Then just remove the section here (edit link in section header, delete text, save). * If veekun is obviously more wrong, check that the wiki has references, and get in touch (e.g. use the talk page here). * Discussions toward better common style and wording guidelines are welcome. """).format( veekun=wiki_colorizers[1]('veekun'), powiki=wiki_colorizers[0]('wiki'), ).encode('utf-8')) header_texts = dict() good_articles = set() bad_articles = set() def yield_wikifiles(): for i in range(50): yield wikifile wikifile.write('\n=Truncated=') wikifile.write('\nThere are too many differences to list them all.') class FakeFile(object): def write(self, s): pass fake_file = FakeFile() while True: yield fake_file yield_wikifile = yield_wikifiles().next def write_diff(diff, veekun_section, name): if diff: term_header = termcolor.colored(name.encode('utf-8'), 'blue') print term_header catfile.write(term_header + b'\n') print_diff(diff) print_diff(diff, catfile) template = '={0}=\n' + re.sub(r'\s+', ' ', """ <div style="float:right;border:1px solid #eee;padding:1ex;white-space:pre;" class="plainlinks">[[{0}|{1}]] ([{{{{fullurl:{0}|action=edit}}}} edit] ◦ [[Talk:{0}|talk]] ◦ [{{{{fullurl:{0}|action=history}}}} history]) ◦ [http://veekun.com/dex/{4}/{2}#effect {3}] </div> """) w_file = yield_wikifile() w_file.write(template.format( name, wiki_colorizers[0]('wiki'), name.lower().replace(' ', '%20'), wiki_colorizers[1]('veekun'), veekun_section, ).encode('utf-8')) w_file.write('<div style="font-family:monospace;white-space:pre;white-space:pre-wrap;">') print_wiki_diff(diff, w_file) w_file.write('</div><br style="clear:both;">\n') print elif diff is False: bad_articles.add(name) else: good_articles.add(name) q = session.query(tables.Move) q = q.options(joinedload('versions')) #q = q.filter_by(identifier='acid-armor') for move in sorted(q, key=lambda m: m.name): wikitext = get_wikitext(move.name, 'move') article = wikiparse.wikiparse(wikitext) diff = analyze_move(article, move) write_diff(diff, 'moves', move.name) for ability in sorted(session.query(tables.Ability), key=lambda m: m.name): wikitext = get_wikitext(ability.name, 'ability') article = wikiparse.wikiparse(wikitext) diff = analyze_ability(article, ability) write_diff(diff, 'abilities', ability.name) ''' for item in sorted(session.query(tables.Item), key=lambda m: m.name): wikitext = get_wikitext(item.name, 'item') article = wikiparse.wikiparse(wikitext) diff = analyze_item(article, item) write_diff(diff, 'items', item.name) ''' wikifile.write('\n') if good_articles: wikifile.write(('\n=Victory! No differences detected=\n' + ', '.join('%s' % n for n in sorted(good_articles))).encode('utf-8')) if bad_articles: wikifile.write(('\n=Pages with no Effect section=\n' + ', '.join('[[%s]]' % n for n in sorted(bad_articles))).encode('utf-8'))