def getCurrentWikis(self): lst = [int(i) for i in self.wikidata] for id in lst: wiki = Wiki(id) wiki.updateFromDump(self.wikidata[id]) wiki.onList = True return lst
def step1(self): output('\n\r\03{lightyellow}Step 1\03{default}: Grabbing lists') output('\03{lightyellow} 1.1\03{default}: Current') A = set(self.getCurrentWikis()) output(' Found \03{{lightaqua}}{:d}\03{{default}} wiki(s)'.format(len(A))) output('\n\r\03{lightyellow} 1.2\03{default}: WAM') if not self.getOption('skipwam'): B = set(self.getWAMWikis()) - A output(' Found \03{{lightaqua}}{:d}\03{{default}} more wiki(s)'.format(len(B))) else: B = set() output(' \03{lightyellow}skipping...\03{default}') output('\n\r\03{lightyellow} 1.3\03{default}: Queued list') if not self.getOption('skipqueue'): C = set(self.getQueuedWikis()) - A - B output(' Found \03{{lightaqua}}{:d}\03{{default}} more wiki(s)'.format(len(C))) else: C = set() output(' \03{lightyellow}skipping...\03{default}') ids = A | B | C if len(ids) == 0: output('\n\r\03{lightyellow}No wikis to work with were found\03{default}') raise pywikibot.bot.QuitKeyboardInterrupt output('\n\rFound \03{{lightaqua}}{:d}\03{{default}} unique wiki id(s) overall'.format(len(ids))) for id in ids: Wiki(id)
class Main(Module): pattern = _pattern require_addressing = True help = 'wikiquote - get random quote from wikiquotes' def __init__(self, madcow=None): self.wiki = Wiki(base_url=_base_url, advert=_advert) def get_random_quote(self, author=_author, max=_max): for i in range(0, max): try: return self._get_random_quote(author=author) except: pass raise Exception, 'no parseable page found :(' def extract_quote(self, obj): li = obj.find('li') contents = li.contents contents = [str(part) for part in contents] quote = ' '.join(contents) quote = stripHTML(quote) quote = _linebreak.sub(' ', quote) quote = _whitespace.sub(' ', quote) quote = quote.strip() return quote def _get_random_quote(self, author=_author): soup, title = self.wiki.get_soup(author) if title == Wiki._error: return "Couldn't find quotes for that.." content = soup.find('div', attrs={'id': 'bodyContent'}) uls = content.findAll('ul', recursive=False) quotes = [] for ul in uls: note = ul.find('ul') if note: note.extract() note = self.extract_quote(note) quote = self.extract_quote(ul) if note: quote = '%s -- %s' % (quote, note) quotes.append(quote) quote = random.choice(quotes) quote = '%s: %s' % (title, quote) return quote def response(self, nick, args, kwargs): try: author = args[0] if author: max = 1 else: author = _author max = _max return self.get_random_quote(author=author, max=max) except Exception, e: log.warn('error in %s: %s' % (self.__module__, e)) log.exception(e) return '%s: problem with query: %s' % (nick, e)
def step2(self): output('\n\r\03{lightyellow}Step 2\03{default}: Fetching base info and processing') ids = [id for id in allWikis] lst = api.getDetails(ids) for id in ids: wiki = Wiki(id) try: wiki.updateFromAPI(lst[str(id)]) except KeyError: wiki.__class__ = ClosedWiki if wiki.onList else InvalidWiki if isinstance(wiki, ClosedWiki): if wiki.onList: self.toRemove.add(wiki) wiki.status = 'closed' self.addToTable('lightred', id, wiki) elif isinstance(wiki, InvalidWiki): wiki.status = 'invalid' self.addToTable('gray', id, wiki) elif self.settings['languages'] is not None and wiki.language not in self.settings['languages']: if wiki.onList: self.toRemove.add(wiki) wiki.status = 'badlang' self.addToTable('lightpurple', id, wiki) elif not wiki.onList: self.toAdd.add(wiki) wiki.status = 'new' self.addToTable('lightgreen', id, wiki) else: self.toUpdate.add(wiki) wiki.status = ' ' self.addToTable('default', id, wiki) self.printLogTable()
class Main(Module): pattern = re.compile('^\s*(?:wp|wiki|wikipedia)\s+(.*?)\s*$', re.I) require_addressing = True help = 'wiki <term> - look up summary of term on wikipedia' def __init__(self, *args, **kwargs): self.wiki = Wiki() def response(self, nick, args, kwargs): try: return self.wiki.get_summary(args) except Exception, e: log.warn('error in %s: %s' % (self.__module__, e)) log.exception(e) return '%s: problem with query: %s' % (nick, e)
class Main(Module): pattern = re.compile('^\s*(?:cp)\s+(.*?)\s*$', re.I) require_addressing = True help = 'cp <term> - look up summary of term on conservapedia' def __init__(self, madcow=None): self.wiki = Wiki(base_url=_baseurl, random_path=_random_path, advert=_advert) def response(self, nick, args, kwargs): try: return self.wiki.get_summary(args) except Exception, e: log.warn('error in %s: %s' % (self.__module__, e)) log.exception(e) return '%s: problem with query: %s' % (nick, e)
def __init__(self, madcow=None): self.wiki = Wiki(base_url=_baseurl, random_path=_random_path, advert=_advert)
def __init__(self, *args, **kwargs): self.wiki = Wiki()
def __init__(self, madcow=None): self.wiki = Wiki(base_url=_base_url, advert=_advert)