def main(app):
    global TITLES, REDIRECTS
    start = time.time()
    print "Starting title server..."

    options = define_options()
    lb = LoadBalancer(options.dbconfig)
    global_db = lb.get_db_by_name('wikicities')
    (wiki_id, dbname) = get_local_db_from_options(options, global_db)
    local_db = lb.get_db_by_name(dbname)

    # store flat, unique dictionary
    cursor = local_db.cursor()
    cursor.execute("SELECT page_title FROM page WHERE page_namespace IN (%s)" %
                   ", ".join(map(str, get_namespaces(global_db, wiki_id))))
    TITLES = set(map(lambda x: preprocess(x[0]), cursor))

    # relate preprocessed redirect title to canonical title
    cursor = local_db.cursor()
    cursor.execute(
        "SELECT page_title, rd_title FROM redirect INNER JOIN page ON page_id = rd_from"
    )
    REDIRECTS = dict([map(preprocess, row) for row in cursor])

    print "Title server ready in %s seconds" % str(time.time() - start)
    app.run(debug=True, host='0.0.0.0', port=5001)
Beispiel #2
0
 def initDb(self):
     dbyml = os.environ.get('WIKIA_DB_YML', '/usr/wikia/conf/current/DB.yml')
     lb = LoadBalancer(dbyml)
     globalDb = lb.get_db_by_name('wikicities')
     cursor = globalDb.cursor()
     cursor.execute('SELECT city_dbname FROM city_list WHERE city_url = "%s"' % (self.host))
     result = cursor.fetchone()
     self.db = lb.get_db_by_name(result[0])
Beispiel #3
0
 def getIterator(self):
     lb = LoadBalancer(self.options.get('dbconf', '/usr/wikia/conf/current/DB.yml'))
     globalDb = lb.get_db_by_name('wikicities')
     cursor = globalDb.cursor()
     self.results = cursor.execute(self.getQuery())
     self.progress = 0
     return cursor
Beispiel #4
0
 def getIterator(self):
     lb = LoadBalancer(
         self.options.get('dbconf', '/usr/wikia/conf/current/DB.yml'))
     globalDb = lb.get_db_by_name('wikicities')
     cursor = globalDb.cursor()
     self.results = cursor.execute(self.getQuery())
     self.progress = 0
     return cursor
Beispiel #5
0
def get_global_db(master=False):
    """
    Accesses the wikia global db
    :param master: whether we should use the writeable master db
    :type master: bool
    :return: database connection
    """
    lb = LoadBalancer(get_config())
    return lb.get_db_by_name('wikicities', master=master)
Beispiel #6
0
def get_global_db(master=False):
    """
    Accesses the wikia global db

    :param master: whether we should use the writeable master db
    :type master: bool

    :return: database connection
    :rtype: MySQLdb.connections.Connection

    """
    lb = LoadBalancer(get_config())
    return lb.get_db_by_name('wikicities', master=master)
def main(app):
    global TITLES, REDIRECTS
    start = time.time()
    print "Starting title server..."

    options = define_options()
    lb = LoadBalancer(options.dbconfig)
    global_db = lb.get_db_by_name('wikicities')
    (wiki_id, dbname) = get_local_db_from_options(options, global_db)
    local_db = lb.get_db_by_name(dbname)

    # store flat, unique dictionary
    cursor = local_db.cursor()
    cursor.execute("SELECT page_title FROM page WHERE page_namespace IN (%s)" % ", ".join(map(str, get_namespaces(global_db, wiki_id))))
    TITLES = set(map(lambda x: preprocess(x[0]), cursor))

    # relate preprocessed redirect title to canonical title
    cursor = local_db.cursor()
    cursor.execute("SELECT page_title, rd_title FROM redirect INNER JOIN page ON page_id = rd_from")
    REDIRECTS = dict([map(preprocess, row) for row in cursor])

    print "Title server ready in %s seconds" % str(time.time() - start)
    app.run(debug=True, host='0.0.0.0', port=5001)
def get_global_db():
    lb = LoadBalancer(get_config())
    return lb.get_db_by_name('wikicities')
def get_global_db(master=False):
    lb = LoadBalancer(get_config())
    return lb.get_db_by_name('wikicities', master=master)
def get_global_db():
    lb = LoadBalancer(get_config())
    return lb.get_db_by_name('wikicities')