def listFromTitles(site, titles, check=True, followRedir=False): """Create a list of page objects from a list of titles check and followRedir have the same meaning as in page.Page """ ret = [] if not check: for title in titles: title = page.Page(site, title=title, check=False) ret.append(title) else: querylist = [] limit = int(site.limit) if len(titles) > limit / 10: iters = int(math.ceil(float(len(titles)) / (limit / 10))) for x in range(0, iters): lower = x * limit / 10 upper = (x + 1) * limit / 10 querylist.append(titles[lower:upper]) else: querylist.append(titles) response = False for item in querylist: tlist = '|'.join(item) if not isinstance(tlist, unicode): tlist = unicode(tlist, 'utf8') params = { 'action': 'query', 'titles': tlist, } if followRedir: params['redirects'] = '' req = api.APIRequest(site, params) res = req.query(False) if not response: response = res else: # This breaks on non-existent titles, the api gives them negative numbers # resultCombine doesn't account for this and ignores or overwrites the # duplicate pageids response = api.resultCombine('', response, res) for key in response['query']['pages'].keys(): res = response['query']['pages'][key] item = makePage(key, res, site) ret.append(item) return ret
def listFromTitles(site, titles, check=True, followRedir=False): """Create a list of page objects from a list of titles check and followRedir have the same meaning as in page.Page """ ret = [] if not check: for title in titles: title = page.Page(site, title=title, check=False) ret.append(title) else: querylist = [] limit = int(site.limit) if len(titles) > limit/10: iters = int(math.ceil(float(len(titles)) / (limit/10))) for x in range(0,iters): lower = x*limit/10 upper = (x+1)*limit/10 querylist.append(titles[lower:upper]) else: querylist.append(titles) response = False for item in querylist: tlist = '|'.join(item) if not isinstance(tlist, unicode): tlist = unicode(tlist, 'utf8') params = {'action':'query', 'titles':tlist, } if followRedir: params['redirects'] = '' req = api.APIRequest(site, params) res = req.query(False) if not response: response = res else: # This breaks on non-existent titles, the api gives them negative numbers # resultCombine doesn't account for this and ignores or overwrites the # duplicate pageids response = api.resultCombine('', response, res) for key in response['query']['pages'].keys(): res = response['query']['pages'][key] item = makePage(key, res, site) ret.append(item) return ret
def listFromPageids(site, pageids, check=True, followRedir=False): """Create a list of page objects from a list of pageids check and followRedir have the same meaning as in page.Page """ ret = [] if not check: for id in pageids: title = page.Page(site, pageid=id, check=False) ret.append(title) else: querylist = [] limit = int(site.limit) if len(pageids) > limit / 10: iters = int(math.ceil(float(len(pageids)) / (limit / 10))) for x in range(0, iters): lower = x * limit / 10 upper = (x + 1) * limit / 10 querylist.append(pageids[lower:upper]) else: querylist.append(pageids) response = False for item in querylist: ids = [str(id) for id in item] idlist = '|'.join(ids) params = { 'action': 'query', 'pageids': idlist, } if followRedir: params['redirects'] = '' req = api.APIRequest(site, params) res = req.query() if not response: response = res else: response = api.resultCombine('', response, res) for key in response['query']['pages'].keys(): res = response['query']['pages'][key] item = makePage(key, res, site) ret.append(item) return ret
def listFromPageids(site, pageids, check=True, followRedir=False): """Create a list of page objects from a list of pageids check and followRedir have the same meaning as in page.Page """ ret = [] if not check: for id in pageids: title = page.Page(site, pageid=id, check=False) ret.append(title) else: querylist = [] limit = int(site.limit) if len(pageids) > limit/10: iters = int(math.ceil(float(len(pageids)) / (limit/10))) for x in range(0,iters): lower = x*limit/10 upper = (x+1)*limit/10 querylist.append(pageids[lower:upper]) else: querylist.append(pageids) response = False for item in querylist: ids = [str(id) for id in item] idlist = '|'.join(ids) params = {'action':'query', 'pageids':idlist, } if followRedir: params['redirects'] = '' req = api.APIRequest(site, params) res = req.query() if not response: response = res else: response = api.resultCombine('', response, res) for key in response['query']['pages'].keys(): res = response['query']['pages'][key] item = makePage(key, res, site) ret.append(item) return ret