Added output of interface log file result.log, fixed weight sorting anomaly

This commit is contained in:
guorong.zheng 2024-03-18 14:28:01 +08:00
parent 52e95b94f2
commit cd09200dc3
4 changed files with 11 additions and 10 deletions

@ -55,7 +55,8 @@ Customize channel menus, automatically fetch and update the latest live source i
- Added configuration item: ipv_type, used to filter ipv4, ipv6 interface types
- Optimized file update logic to prevent file loss caused by update failure
- Adjusted the default value for pagination: fetch 6 pages for followed channels, 4 pages for regular channels, to improve update speed
- Added output saving of interface log files
- Added output of interface log file result.log
- Fixed weight sorting anomaly
### 2024/3/15

@ -55,7 +55,8 @@
- 新增配置项ipv_type用于过滤 ipv4、ipv6 接口类型
- 优化文件更新逻辑,避免更新失效引起文件丢失
- 调整分页获取默认值:关注频道获取 6 页,常规频道获取 4 页,以提升更新速度
- 增加接口日志文件输出保存
- 增加接口日志文件 result.log 输出
- 修复权重排序异常
### 2024/3/15

@ -21,6 +21,7 @@ import logging
logging.basicConfig(
filename="result_new.log",
filemode="a",
format="%(message)s",
level=logging.INFO,
)

@ -93,12 +93,12 @@ async def getSpeed(url):
async with session.get(url, timeout=5) as response:
resStatus = response.status
except:
return url, float("inf")
return float("inf")
end = time.time()
if resStatus == 200:
return url, int(round((end - start) * 1000))
return int(round((end - start) * 1000))
else:
return url, float("inf")
return float("inf")
async def compareSpeedAndResolution(infoList):
@ -107,9 +107,7 @@ async def compareSpeedAndResolution(infoList):
"""
response_times = await asyncio.gather(*(getSpeed(url) for url, _, _ in infoList))
valid_responses = [
(info, rt)
for info, rt in zip(infoList, response_times)
if rt[1] != float("inf")
(info, rt) for info, rt in zip(infoList, response_times) if rt != float("inf")
]
def extract_resolution(resolution_str):
@ -139,11 +137,11 @@ async def compareSpeedAndResolution(infoList):
(_, _, resolution), response_time = item
resolution_value = extract_resolution(resolution) if resolution else 0
return (
-(response_time_weight * response_time[1])
-(response_time_weight * response_time)
+ resolution_weight * resolution_value
)
sorted_res = sorted(valid_responses, key=combined_key)
sorted_res = sorted(valid_responses, key=combined_key, reverse=True)
return sorted_res