Merge branch 'master' into master

This commit is contained in:
落落
2022-06-23 22:03:08 +08:00
committed by GitHub
6 changed files with 55 additions and 10 deletions

3
.gitignore vendored
View File

@@ -1,3 +1,6 @@
# owner
git-filter-repo.py
replacements.txt
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

9
celery_server/tasks.py Normal file
View File

@@ -0,0 +1,9 @@
from .celery import app
from .celery import logger
import time
@app.task
def test(x, y):
logger.info("开始执行 test() 方法")
time.sleep(5)
logger.info("test() 方法执行成功")

View File

@@ -11,7 +11,9 @@ import asyncio
import click
import httpx
from utils import default_header_user_agent
from utils.log import logger
from utils.models import API
from utils.req import reqFunc, runAsync
@@ -109,11 +111,18 @@ def run(thread: int, phone: Union[str, tuple], frequency: int):
# for api_get in _api_get:
# _process = pool.submit(reqFunc, api_get, phone, proxy)
for api in _api:
_process = pool.submit(reqFunc, api, phone, proxy)
# 在这里设置List后使用for _p in list, _p.result()会报错, 故限定最后一个
_process.result()
logger.success(f"{i}波轰炸 - 代理:" + proxy['all://'] + " 轰炸完成,准备进行下一步操作...")
logger.success(f"{i}波轰炸结束!")
pool.submit(reqFunc, api, phone)
for api_get in _api_get:
pool.submit(reqFunc, api_get, phone)
logger.success(f"{i}波轰炸提交结束!休息{interval}s.....")
time.sleep(interval)
else:
for api in _api:
pool.submit(reqFunc, api, phone)
for api_get in _api_get:
pool.submit(reqFunc, api_get, phone)
@click.option("--phone", "-p", help="手机号,可传入多个再使用-p传递", prompt=True, required=True, multiple=True)
@@ -122,8 +131,10 @@ def asyncRun(phone):
"""以最快的方式请求接口(真异步百万并发)"""
_api = load_json()
_api_get = load_getapi()
apis = _api + _api_get
loop = asyncio.get_event_loop()
loop.run_until_complete(runAsync(apis, phone))
@@ -134,8 +145,10 @@ def oneRun(phone):
"""单线程(测试使用)"""
_api = load_json()
_api_get = load_getapi()
apis = _api + _api_get
for api in apis:
try:
reqFunc(api, phone)
@@ -177,5 +190,6 @@ cli.add_command(update)
cli.add_command(asyncRun)
cli.add_command(oneRun)
if __name__ == "__main__":
cli()

View File

@@ -1,3 +1,4 @@
import random
USER_AGENT_LIST = [

View File

@@ -4,15 +4,19 @@ from pydantic import BaseModel
from typing import Union, Optional
from datetime import datetime
import json
from utils import default_header_user_agent
class API(BaseModel):
"""处理自定义 API 数据"""
desc: str = "Default"
url: str
method: str = "GET"
header: Optional[Union[str, dict]] = default_header_user_agent()
data: Optional[Union[str, dict]]
def replace_data(self, content: Union[str, dict], phone: str) -> str:
@@ -31,7 +35,8 @@ class API(BaseModel):
"""返回整数字符串时间戳"""
return str(int(datetime.now().timestamp()))
def handle_API(self, phone: str = None):
def handle_API(self, phone: str=None):
""" 传入手机号处理 API
:param API: one API basemodel
:return: API basemodel

View File

@@ -5,7 +5,9 @@ from httpx import Limits
from typing import Union, List
import asyncio
from utils import default_header_user_agent
from utils.models import API
from utils.log import logger
@@ -20,7 +22,9 @@ def reqAPI(api: API, client: Union[httpx.Client, httpx.AsyncClient]) -> httpx.Re
return resp
def reqFunc(api: Union[API, str], phone: Union[tuple, str], proxy: dict) -> bool:
"""请求接口方法"""
# 多手机号支持
if isinstance(phone, tuple):
@@ -28,27 +32,33 @@ def reqFunc(api: Union[API, str], phone: Union[tuple, str], proxy: dict) -> bool
else:
phone_lst = [phone]
with httpx.Client(headers=default_header_user_agent(), verify=False, proxies=proxy) as client:
for ph in phone_lst:
try:
if isinstance(api, API):
api = api.handle_API(ph)
resp = reqAPI(api, client)
logger.info(f"{api.desc}-{resp.text[:30]}-当前使用代理:{proxy['all://']}")
logger.info(f"{api.desc}-{resp.text[:30]}")
else:
api = api.replace("[phone]", ph).replace(" ", "").replace('\n', '').replace('\r', '')
resp = client.get(url=api, headers=default_header)
logger.info(f"GETAPI接口-{resp.text[:30]}-当前使用代理:{proxy['all://']}")
logger.info(f"GETAPI接口-{resp.text[:30]}")
return True
except httpx.HTTPError as why:
logger.error(f"请求失败{why}-当前使用代理:{proxy['all://']}")
logger.error(f"请求失败{why}")
return False
async def asyncReqs(src: Union[API, str], phone: Union[tuple, str], semaphore):
"""异步请求方法
:param:
:return:
"""
# 多手机号支持
if isinstance(phone, tuple):
@@ -94,7 +104,10 @@ def callback(result):
logger.info(f"请求结果:{log.text[:30]}")
async def runAsync(apis: List[Union[API, str]], phone: Union[tuple, str]):
async def runAsync(apis: List[Union[API,str]], phone: Union[tuple, str]):
tasks = []
for api in apis: