def location(clientIP, i): if clientIP != None: if ip.find(clientIP) != None: if len(unidecode(ip.find(clientIP)).split("\t")) == 3: location = unidecode(ip.find(clientIP)).split("\t") city = location[i] else: city = "unknown" else: city = "unknown" else: city = "unknown" return city
def test_domain(): assert IP.find("localhost") == u("本机地址\t本机地址")
charset='utf8') try: with conn.cursor() as cursor: sql = "select `ip`,`urlid` from `target_ip` where `urlid` > 83871" cursor.execute(sql) output = [] while 1: try: res = cursor.fetchmany(10) if len(res) == 0: #cursor.scroll(0,mode='absolute') break for line in res: ipstr = line[0] urlid = line[1] res = find(ipstr) if res is not None: res = res.split('\t', 3) if len(res) == 3: country, province, city = res if len(res) == 2: counry, province = res city = '' if len(res) ==1: country = res province = city = '' print urlid,country,province,city output.append((urlid, country, province, city)) try: with conn.cursor() as cursor2: insert = r"insert into target_city (id,country,province,city) values (%s,%s,%s,%s) "
def test_ip(): assert IP.find("127.0.0.1") == u("本机地址\t本机地址") assert IP.find("59.151.24.1") == u("中国\t北京\t北京")
PY3 = sys.version_info[0] == 3 if PY3: def u(s): return s else: def u(s): return s.decode('utf-8') import ip as IP def test_ip(): assert IP.find("127.0.0.1") == u("本机地址\t本机地址") assert IP.find("59.151.24.1") == u("中国\t北京\t北京") def test_domain(): assert IP.find("localhost") == u("本机地址\t本机地址") # assert IP.find("ele.me") == u("中国\t北京\t北京") def test_without_mmap(): with IP.IPv4Database(use_mmap=False) as db: assert db.find("127.0.0.1") == u("本机地址\t本机地址") print IP.find("125.39.113.19") print IP.find("www.wuranju.com") print IP.find("113.201.61.106")
def u(s): return s else: def u(s): return s.decode('utf-8') import ip as IP def test_ip(): assert IP.find("127.0.0.1") == u("本机地址\t本机地址") assert IP.find("59.151.24.1") == u("中国\t北京\t北京") def test_domain(): assert IP.find("localhost") == u("本机地址\t本机地址") # assert IP.find("ele.me") == u("中国\t北京\t北京") def test_without_mmap(): with IP.IPv4Database(use_mmap=False) as db: assert db.find("127.0.0.1") == u("本机地址\t本机地址") print IP.find("125.39.113.19") print IP.find("www.wuranju.com") print IP.find("113.201.61.106")