feat: filter proxies by country via ?area=CN (#84, #177) - #233
Merged
Conversation
- redis: add RedisClient.randoms(count, ...) which prefers max-score proxies and falls back to rank, returning a de-duplicated random sample - server: /random accepts a count parameter and returns N random proxies (one per line); count<=1 keeps the original single-proxy behavior; works with key too - README: document the new count parameter Closes #194
- utils/geo: add get_country_iso() backed by the bundled GeoLite2 db (previously an unused dependency); fails safe to None if unavailable - server: /random and /all accept an area parameter (country iso code) to return only proxies from that country; combines with count and key - README: document the area parameter Closes #84, Closes #177
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
Issue 收敛计划 Phase 4b(增强:按国家/地区筛选代理),对应 #84(按国家区分)和 #177(筛选国内 IP)。
亮点:把一个「僵尸依赖」变成功能
maxminddb_geolite2早已在requirements.txt里,但从未被使用。本 PR 用它实现离线 IP→国家解析,无需新增依赖。改动
proxypool/utils/geo.py:get_country_iso(ip)基于内置 GeoLite2 库返回 ISO 国家码;库缺失或解析失败时安全降级返回None(不影响其他功能)。processors/server.py:/random、/all新增area参数,按国家码筛选(大小写不敏感),可与count、key组合。README.md:补充area用法。用法
验证
server.py/geo.py编译通过。8.8.8.8 → US、114.114.114.114 → CN;filter(area=CN)只保留114.114.114.114,filter(area=US)只保留8.8.8.8。area参数时行为完全不变。关联 issue