def __init__(self, page): self.page = page self.title = page.title() self.id = page.id() # self.username = self.page.titlewonamespace() self.username = False self.API = wiki.API(wiki=page.getSite())
def whatlinkshere(page): """ [[Special:WhatLinksHere]] """ API = wiki.API(wiki=page.getSite()) params = { 'action': 'query', 'bltitle': page.title(), 'list': 'backlinks', 'bllimit': 'max', } res = API.query(params)['query']['backlinks'] for i in res: yield wiki.Page(i['title'])
def transclude(page): """ Returns pages that transclude a certain template """ API = wiki.API(wiki=page.getSite()) print 'Getting references to [[%s]]...' % (page.title()) params = { 'action': 'query', 'list': 'embeddedin', 'eititle': page.title(), 'eilimit': 'max', } res = API.query(params) for page in res['query']['embeddedin']: yield wiki.Page(page['title'])
def main(): if len(sys.argv) < 2: # NOTE: The category can be specified with either spaces or underscores. sys.stderr.write("{0} CATEGORY\n".format(sys.argv[0])) sys.exit(1) category = sys.argv[1] wiki_api = wiki.API('wikipedia') #ganfyd_api = wiki.API('ganfyd') #obj = wiki_api.query_category_pages(category) obj = wiki_api.get_category_pages(category) json.dump(obj, sys.stdout, indent=2) sys.stdout.write('\n')
def main(): if len(sys.argv) < 2: sys.stderr.write("{0} URL\n".format(sys.argv[0])) sys.exit(1) url = sys.argv[1] title = get_page_title(url) wiki_api = wiki.API('wikipedia') #ganfyd_api = wiki.API('ganfyd') #obj = wiki_api.query_categories(title) obj = wiki_api.get_page_categories(title) json.dump(obj, sys.stdout, indent=2) sys.stdout.write('\n')
def prefixindex(page): """ Returns list of pages with prefix of the page ([[Special:PrefixIndex]]) """ API = wiki.API(wiki=page.getSite()) ns = page.namespace() prefix = page.titlewonamespace() params = { 'action': 'query', 'list': 'allpages', 'apprefix': prefix, 'apnamespace': str(ns), 'aplimit': 'max', } res = API.query(params)['query']['allpages'] list = [] for page in res: yield wiki.Page(page['title'])
def recentchanges(limit=500, nobot=True, onlyanon=False, hidepatrolled=True, nponly=False, wiki=config.wiki): """ Returns a list of articles that were recently changed ([[Special:RecentChanges]]) If nponly = True, returns only newpages ([[Special:NewPages]]) """ rcshow = [] if nobot: rcshow.append('!bot') if onlyanon: rcshow.append('anon') # if hidepatrolled: # rcshow.append('!patrolled') rcshowparam = '' if len(rcshow) != 0: for i in rcshow: if i == rcshow[len(rcshow) - 1]: #meaning it is the last one.. rcshowparam += i else: rcshowparam += i + '|' params = { 'action': 'query', 'list': 'recentchanges', 'rcshow': rcshowparam, 'rcprop': 'title', 'rclimit': limit } if nponly: print 'Fetching the %s newest pages' % limit params['rctype'] = 'new' else: print 'Fetching the %s latest edits' % limit API = wiki.API(qcontinue=False, wiki=wiki) res = API.query(params)['query']['recentchanges'] for page in res: yield wiki.Page(page['title'])
def __init__(self, page): self.page = page self.title = page.title() self.id = page.id() self.API = wiki.API(wiki=page.getSite())