mirror of
https://github.com/ClovertaTheTrilobita/SanYeCao-Nonebot.git
synced 2026-04-01 22:04:51 +00:00
refactor(clover_image): 使用 aiohttp 替代 requests 发送异步请求
This commit is contained in:
parent
a6f82b8a30
commit
a5d7a549f3
3 changed files with 20 additions and 18 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
import os
|
import os
|
||||||
import random
|
import random
|
||||||
import requests
|
import aiohttp
|
||||||
|
|
||||||
from src.configs.path_config import image_local_path
|
from src.configs.path_config import image_local_path
|
||||||
from src.configs.api_config import smms_token,smms_image_upload_history,ju_he_token,ju_he_image_list,anosu_url
|
from src.configs.api_config import smms_token,smms_image_upload_history,ju_he_token,ju_he_image_list,anosu_url
|
||||||
|
|
@ -18,25 +18,29 @@ async def get_image_names():
|
||||||
|
|
||||||
""" sm.ms 图床"""
|
""" sm.ms 图床"""
|
||||||
async def get_smms_image_url():
|
async def get_smms_image_url():
|
||||||
# 定义请求的参数
|
async with aiohttp.ClientSession() as session:
|
||||||
data = requests.get(smms_image_upload_history, headers={'Authorization': smms_token}, params={"page": "1"}).json().get('data')
|
async with session.get(smms_image_upload_history, headers={'Authorization': smms_token}, params={"page": "1"}) as response:
|
||||||
urls = [item['url'] for item in data]
|
data = await response.json()
|
||||||
random_url = random.choice(urls)
|
urls = [item['url'] for item in data.get('data', [])]
|
||||||
return random_url
|
random_url = random.choice(urls)
|
||||||
|
return random_url
|
||||||
|
|
||||||
"""聚合图床"""
|
"""聚合图床"""
|
||||||
async def get_juhe_image_url():
|
async def get_juhe_image_url():
|
||||||
# 定义请求的参数
|
params = {"token": ju_he_token, "f": "json", "categories": "猫羽雫", "page": 1, "size": 400}
|
||||||
params = {"token": ju_he_token,"f": "json","categories": "猫羽雫","page": 1, "size": 400}
|
async with aiohttp.ClientSession() as session:
|
||||||
random_url = random.choice(requests.get(ju_he_image_list, params=params).json().get('docs', [])).get('url')
|
async with session.get(ju_he_image_list, params=params) as response:
|
||||||
return random_url
|
data = await response.json()
|
||||||
|
random_url = random.choice(data.get('docs', [])).get('url')
|
||||||
|
return random_url
|
||||||
|
|
||||||
"""
|
"""
|
||||||
随机图api
|
随机图api
|
||||||
"""
|
"""
|
||||||
|
async def get_anosu_image(keyword: str, is_r18: int, num: int, proxy: str = "i.pixiv.re"):
|
||||||
async def get_anosu_image(keyword : str ,is_r18 : int,num : int,proxy : str = "i.pixiv.re"):
|
url = anosu_url + f"?keyword={keyword}&r18={is_r18}&num={num}&proxy={proxy}"
|
||||||
url= anosu_url+f"?keyword={keyword}&r18={is_r18}&num={num}&proxy={proxy}"
|
async with aiohttp.ClientSession() as session:
|
||||||
data = requests.get(url).json()
|
async with session.get(url) as response:
|
||||||
urls = [item['url'] for item in data]
|
data = await response.json()
|
||||||
return urls
|
urls = [item['url'] for item in data]
|
||||||
|
return urls
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
import os
|
import os
|
||||||
import aiohttp
|
import aiohttp
|
||||||
import requests
|
|
||||||
|
|
||||||
from src.configs.path_config import image_local_qq_image_path
|
from src.configs.path_config import image_local_qq_image_path
|
||||||
from src.configs.api_config import app_id,bot_account
|
from src.configs.api_config import app_id,bot_account
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from lazy_object_proxy.utils import await_
|
|
||||||
from nonebot.rule import to_me
|
from nonebot.rule import to_me
|
||||||
from nonebot.plugin import on_command
|
from nonebot.plugin import on_command
|
||||||
from nonebot.adapters.qq import Message, MessageEvent, MessageSegment
|
from nonebot.adapters.qq import Message, MessageEvent, MessageSegment
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue