uu_pixiv_api / getNode.py
rogerxavier's picture
Update getNode.py
134508d verified
raw
history blame
1.08 kB
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
from server.decoder import decode_url_to_configs
from server.utils import config,headers
import random
from fastapi import APIRouter,BackgroundTasks
from randomSubscribeUrl import subscription_link_list,getRandomSubscribeUrl,delete_invalid_url_in_txt
router = APIRouter()
@router.get('/')
def getNode(background_tasks: BackgroundTasks)->str:
# 返回一个可用的订阅链接信息
SubscribeUrlList = subscription_link_list(router.fileName)
# 直接用现成的认为可用然后直接返回,之后再删不可用的
randomSubscribeUrl= getRandomSubscribeUrl(SubscribeUrlList)
NodeList = dump_configs(randomSubscribeUrl)
NodeStr = RandomNode(NodeList)
#background_tasks.add_task(delete_invalid_url_in_txt, router.fileName)
return NodeStr
def RandomNode(NodeList:list)->str:
#返回一个节点信息
return random.choice(NodeList)
def dump_configs(url:str)->list:
#返回全部节点信息的列表
configs = decode_url_to_configs(url)
return configs