Files
to_session/flaskProject1/app.py
Administrator a0720d80dc fefdwef
2025-11-12 12:54:37 +08:00

130 lines
3.5 KiB
Python

import random
import time
from bs4 import BeautifulSoup
from curl_cffi import requests
from flask import Flask, request, jsonify
from loguru import logger
from models.tg_models import ServerInfo, TelegramAccount
from process.tg_process import TG
from tools123123.email123 import get_verify_code
app = Flask(__name__)
@app.route('/start')
def hello_world(): # put application's code here
ld_name = request.args.get('ld_name') # 获取查询参数
if not ld_name:
return "缺少查询参数", 400 # 如果没有提供查询参数,返回错误
if action_type:
phone_data = TelegramAccount().get_or_none(TelegramAccount.ld_name == ld_name)
else:
phone_data = ServerInfo().get_or_none(ServerInfo.telephone == ld_name)
tg = TG(type1=action_type, tg_phone=phone_data, )
if tg.get_code():
logger.error(f"{ld_name},打开成功,账号有问题!!!")
return "账号掉了!!!", 500
logger.info(f"{ld_name},打开成功,账号没有问题!!!")
return "成功!!!", 200
@app.route('/get_code')
def get_code(): # put application's code here
ld_name = request.args.get('ld_name') # 获取查询参数
if not ld_name:
return "缺少查询参数", 400 # 如果没有提供查询参数,返回错误
if action_type:
phone_data = TelegramAccount().get_or_none(TelegramAccount.ld_name == ld_name)
else:
phone_data = ServerInfo().get_or_none(ServerInfo.telephone == ld_name)
tg = TG(type1=action_type, tg_phone=phone_data, )
try:
code = tg.get_code1()
response_data = {"codes": code[-1]}
logger.info(f"{ld_name},获取验证码成功!!!")
return jsonify(response_data), 200
except Exception as e:
logger.error(f"{ld_name},获取验证码失败!!!")
return '获取验证码失败!!!', 500
@app.route('/close')
def get_code1(): # put application's code here
ld_name = request.args.get('ld_name') # 获取查询参数
if not ld_name:
return "缺少查询参数", 400 # 如果没有提供查询参数,返回错误
if action_type:
phone_data = TelegramAccount().get_or_none(TelegramAccount.ld_name == ld_name)
else:
phone_data = ServerInfo().get_or_none(ServerInfo.telephone == ld_name)
tg = TG(type1=action_type, tg_phone=phone_data, )
tg.close_ldplayer()
return "成功!!!", 200
@app.route('/get_id')
def get_code2(): # put application's code here
email1 = request.args.get('email') # 获取查询参数
# 接收验证码
code = get_verify_code(email1, 1)
print(code)
soup = BeautifulSoup(code, 'html.parser')
# 筛选所有target="_blank"的a标签
a_tags = soup.find_all('a')
# 提取href属性
href_list = [a['href'] for a in a_tags if a.get('href')]
code = href_list[1] # 输出:['https://example.com/page1', 'https://example.com/page3']
return code, 200
@app.route('/get_url')
def get_url(): # put application's code here
email1 = request.args.get('email') # 获取查询参数
# 接收验证码
code = get_verify_code(email1, 1)
print(code)
soup = BeautifulSoup(code, 'html.parser')
# 筛选所有target="_blank"的a标签
a_tags = soup.find_all('a')
# 提取href属性
href_list = [a['href'] for a in a_tags if a.get('href')]
code = href_list[0] # 输出:['https://example.com/page1', 'https://example.com/page3']
return code, 200
if __name__ == '__main__':
action_type = 1
app.run(host='0.0.0.0', port=8080)