def MySQLPageGenerator(query, site = None): import MySQLdb as mysqldb if site is None: site = pywikibot.getSite() conn = mysqldb.connect(config.db_hostname, db = site.dbName(), user = config.db_username, passwd = config.db_password) cursor = conn.cursor() pywikibot.output(u'Executing query:\n%s' % query) query = query.encode(site.encoding()) cursor.execute(query) while True: try: namespaceNumber, pageName = cursor.fetchone() print namespaceNumber, pageName except TypeError: # Limit reached or no more results break #print pageName if pageName: namespace = site.namespace(namespaceNumber) pageName = unicode(pageName, site.encoding()) if namespace: pageTitle = '%s:%s' % (namespace, pageName) else: pageTitle = pageName page = pywikibot.Page(site, pageTitle) yield page
def new_page(): titles=[] query="select /* SLOW_OK */ rc_title from recentchanges join page on rc_cur_id=page_id where rc_new=1 and rc_namespace=0 and page_is_redirect=0 and page.page_len>70 and rc_deleted=0 and DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 3 DAY)>rc_timestamp GROUP BY rc_timestamp DESC LIMIT 2020;" conn = mysqldb.connect("fawiki.labsdb", db = faSite.dbName(),user = config.db_username,passwd = config.db_password) cursor = conn.cursor() query = query.encode(faSite.encoding()) cursor.execute(query) results = cursor.fetchall() for raw in results: titles.append(unicode(raw[0],'UTF-8')) return titles
def new_page(): titles = [] query = "select /* SLOW_OK */ rc_title from recentchanges join page on rc_cur_id=page_id where rc_new=1 and rc_namespace=0 and page_is_redirect=0 and page.page_len>70 and rc_deleted=0 and DATE_SUB(CURRENT_TIMESTAMP, INTERVAL 3 DAY)>rc_timestamp GROUP BY rc_timestamp DESC LIMIT 2020;" conn = mysqldb.connect("fawiki.labsdb", db=faSite.dbName(), user=config.db_username, passwd=config.db_password) cursor = conn.cursor() query = query.encode(faSite.encoding()) cursor.execute(query) results = cursor.fetchall() for raw in results: titles.append(unicode(raw[0], 'UTF-8')) return titles