Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. def get_pages_by_category(wikidb, category, ns=None):
  2.   query = '''                                                                    
  3.    SELECT page_namespace, page_title, page_id, cl_sortkey, cl_timestamp          
  4.  ''' + '''                                                                      
  5.    FROM ''' + Page.table_name + '''  /* SLOW_OK */                              
  6.    JOIN categorylinks ON page_id = cl_from                                      
  7.    WHERE cl_to = %(category)s                                                    
  8.  '''
  9.  
  10.   params = {'category': category}
  11.   if ns is not None:
  12.     query += ' AND page_namespace = %(ns)s'
  13.     params['ns'] = ns
  14.  
  15.   with wikidb.cursor() as cursor:
  16.     cursor.execute(query, params)
  17.     while True:
  18.       results = cursor.fetchmany(PAGE_BY_CAT_ROWS)
  19.       if not results:
  20.         break
  21.       for result in results:
  22.         yield Page(**result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement