miui-auto-tasks/utils/request.py
Night-stars-1 56c27977da
feat: 重构项目 (#138)
* 修复无法获取成长值的问题

更改成长值获取接口

* 修复无法获取成长值的问题

更改成长值获取接口

* 改用正则获取成长值

* 推送配置说明

* 更新推送

* 更新推送

* Update config.yaml

* Update config.yaml

* Update requirements.txt

* Update config.yaml

* format the file

* 提升版本号

* 提升版本号

* 提升版本号

* 修复取消点赞出错

* feat: 重构项目

* chore: add Exception

* add: repo report link

* feat: 添加token的获取

* chore: 修正签到参数

* Delete utils directory

* Delete config.yaml

* Delete miuitask.py

* feat: 重构项目

* Create __init__.py

* feat: 重构项目

* Create 1

* feat: 重构项目

* add: 添加cryptography依赖

* Delete utils/api/1

* chore: 使用yaml储存数据

* chore: 添加token异常提示
chore: 修正部分数据结构

* imp: add system info output

* imp: auto reformat by PyCharm

* imp: 增加鸣谢

* imp: 修改主程序名称

* fix: 添加被删除的文件

* imp: 根据新版本 修改GitHub Action 脚本

* add: 添加tenacity重试库,部分get_token添加重试机制
chore: 将token.py重命名为utils.py
chore: 添加captcha.py,用于用户自行解决验证码

* 增加信息显示

增加显示项目信息及系统信息

* imp: 修复github action 脚本

* imp: auto reformat by PyCharm

---------

Co-authored-by: 0-8-4 <ljd69154@liangjundi.cn>
Co-authored-by: TardisX <ranoklx@gmail.com>
2023-11-14 00:18:59 +11:00

78 lines
2.1 KiB
Python

"""
Date: 2023-11-11 23:34:08
LastEditors: Night-stars-1 nujj1042633805@gmail.com
LastEditTime: 2023-11-13 18:17:50
"""
import httpx
from typing import Any, Dict, Optional
from onepush import notify
from .logger import log
from .config import ConfigManager
_conf = ConfigManager.data_obj
async def get(url: str,
*,
headers: Optional[Dict[str, str]] = None,
params: Optional[Dict[str, Any]] = None,
timeout: Optional[int] = 20,
**kwargs) -> httpx.Response:
"""
说明:
httpx的get请求封装
参数:
:param url: url
:param headers: 请求头
:param params: params
:param data: data
:param json: json
:param timeout: 超时时间
"""
async with httpx.AsyncClient() as client:
return await client.get(url,
headers=headers,
params=params,
timeout=timeout,
**kwargs)
async def post(url: str,
*,
headers: Optional[Dict[str, str]] = None,
params: Optional[Dict[str, Any]] = None,
timeout: Optional[int] = 20,
**kwargs) -> httpx.Response:
"""
说明:
httpx的post请求封装
参数:
:param url: url
:param headers: 请求头
:param params: params
:param data: data
:param json: json
:param timeout: 超时时间
"""
async with httpx.AsyncClient() as client:
return await client.post(url,
headers=headers,
params=params,
timeout=timeout,
**kwargs)
def notify_me(content=""):
"""
默认推送日志
"""
notifier = _conf.ONEPUSH.notifier
params = _conf.ONEPUSH.params
if not notifier or not params:
log.error('未配置推送或未正确配置推送')
return
return notify(notifier, content=content, **params)