This action will force synchronization from 狮子的魂/ip2region, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
# Copyright 2022 The Ip2Region Authors. All rights reserved.# Use of this source code is governed by a Apache2.0-style# license that can be found in the LICENSE file.#from xdbSearcher import XdbSearcherdef searchWithFile():# 1. 创建查询对象dbPath = "../../data/ip2region.xdb"searcher = XdbSearcher(dbfile=dbPath)# 2. 执行查询ip = "1.2.3.4"region_str = searcher.searchByIPStr(ip)print(region_str)# 3. 关闭searchersearcher.close()def searchWithVectorIndex():# 1. 预先加载整个 xdbdbPath = "../../data/ip2region.xdb"vi = XdbSearcher.loadVectorIndexFromFile(dbfile=dbPath)# 2. 使用上面的缓存创建查询对象, 同时也要加载 xdb 文件searcher = XdbSearcher(dbfile=dbPath, vectorIndex=vi)# 3. 执行查询ip = "1.2.3.4"region_str = searcher.search(ip)print(region_str)# 4. 关闭searchersearcher.close()def searchWithContent():# 1. 预先加载整个 xdbdbPath = "../../data/ip2region.xdb";cb = XdbSearcher.loadContentFromFile(dbfile=dbPath)# 2. 仅需要使用上面的全文件缓存创建查询对象, 不需要传源 xdb 文件searcher = XdbSearcher(contentBuff=cb)# 3. 执行查询ip = "1.2.3.4"region_str = searcher.search(ip)print(region_str)# 4. 关闭searchersearcher.close()if __name__ == '__main__':searchWithContent()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。