def listFromQuery(site, queryresult): """Generate a list of pages from an API query result queryresult is the list of pages from a list or generator query e.g. - for a list=categorymembers query, use result['query']['categorymembers'] for a generator query, use result['query']['pages'] """ ret = [] if isinstance(queryresult, list): for item in queryresult: pageid = False if 'pageid' in item: pageid = item['pageid'] if item['ns'] == 14: item = category.Category(site, title=item['title'], check=False, followRedir=False, pageid=pageid) elif item['ns'] == 6: item = wikifile.File(site, title=item['title'], check=False, followRedir=False, pageid=pageid) else: item = page.Page(site, title=item['title'], check=False, followRedir=False, pageid=pageid) ret.append(item) else: for key in queryresult.keys(): item = queryresult[key] pageid = False if 'pageid' in item: pageid = item['pageid'] if item['ns'] == 14: item = category.Category(site, title=item['title'], check=False, followRedir=False, pageid=pageid) elif item['ns'] == 6: item = wikifile.File(site, title=item['title'], check=False, followRedir=False, pageid=pageid) else: item = page.Page(site, title=item['title'], check=False, followRedir=False, pageid=pageid) ret.append(item) return ret
def makePage(key, result, site): title = False if 'title' in result: title = result['title'] if 'ns' in result and result['ns'] == 14: item = category.Category(site, title=title, check=False, followRedir=False, pageid=key) elif 'ns' in result and result['ns'] == 6: item = wikifile.File(site, title=title, check=False, followRedir=False, pageid=key) else: item = page.Page(site, title=title, check=False, followRedir=False, pageid=key) if 'missing' in result: item.exists = False if 'invalid' in result: item = False if 'ns' in result: item.setNamespace(int(result['ns'])) return item