SHARE
TWEET

Untitled

a guest Jun 18th, 2019 41 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top