def connect_to_user_database(user_db_port=None): """ Establishes connection to database, created by user, in Toolforge. :param user_db_port: port for connecting to db through ssh tunneling, if used. :return: pymysql.connection to the database. """ try: if user_db_port: conn = pymysql.connect( host="127.0.0.1", port=user_db_port, user=cfg['user_credits']['user'], password=cfg['user_credits']['password'], connect_timeout=1000, ) with conn.cursor() as cur: cur.execute("use " + cfg['database_name']) conn.commit() else: conn = toolforge.toolsdb(cfg['database_name'], connect_timeout=1000) return conn except pymysql.err.OperationalError as err: print("Failure: Please establish connection to Toolforge") print("Error: ", err) exit(1)
def connect_to_user_database(db_name, user_db_port=None, user=None, password=None): """ Establishes connection to database, created by user, in Toolforge. :param db_name: name of user's database :param user_db_port: port for connecting to db through ssh tunneling, if used :param user: Toolforge username of the tool :param password: Toolforge password pf the tool :return: pymysql.connection to the database """ try: if user_db_port: conn = pymysql.connect( host="127.0.0.1", port=user_db_port, user=user, password=password, connect_timeout=1000, ) with conn.cursor() as cur: cur.execute("use " + db_name) conn.commit() else: conn = toolforge.toolsdb(db_name, connect_timeout=1000) return conn except pymysql.err.OperationalError as err: print("Failure: Please establish connection to Toolforge") print("Error: ", err) exit(1)
# # get language to process # lang = sys.argv[1] rev = int(sys.argv[2]) # load languages list with open(os.path.join(os.path.dirname(__file__), 'languages.dat')) as lang_file: lang_id = [i.rstrip('\n') for i in lang_file.readlines()].index(lang) print("Processing %s (%d) wiki. Revison %d." % (lang, lang_id, rev)) # # Connect to database (tdb for reading, idb for tile insertion) # tdb = toolforge.toolsdb('s51499__wikiminiatlas') idb = toolforge.toolsdb('s51499__wikiminiatlas') n_tot = 0 n_tile = 0 # # get largest coord_id # with tdb.cursor() as tcr: tcr.execute('SELECT MAX(coord_id) FROM coord_' + lang) global_max_coord = tcr.fetchone()[0] tcr.execute('SELECT MIN(coord_id) FROM coord_' + lang) global_min_coord = tcr.fetchone()[0] print("Found coord_id %d - %d." % (global_min_coord, global_max_coord))