Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_pages_by_category(wikidb, category, ns=None):
- query = '''
- SELECT page_namespace, page_title, page_id, cl_sortkey, cl_timestamp
- ''' + '''
- FROM ''' + Page.table_name + ''' /* SLOW_OK */
- JOIN categorylinks ON page_id = cl_from
- WHERE cl_to = %(category)s
- '''
- params = {'category': category}
- if ns is not None:
- query += ' AND page_namespace = %(ns)s'
- params['ns'] = ns
- with wikidb.cursor() as cursor:
- cursor.execute(query, params)
- while True:
- results = cursor.fetchmany(PAGE_BY_CAT_ROWS)
- if not results:
- break
- for result in results:
- yield Page(**result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement