再次重构

This commit is contained in:
zayac 2024-04-12 15:44:37 +08:00
parent 9e6806c460
commit ddac0c900e

View File

@ -69,6 +69,16 @@ def get_url_mapping(urls_with_context, template_type):
"jyFljPc": categories.get("WEB", ["", ""])[1], "jyFljPc": categories.get("WEB", ["", ""])[1],
"jyFljH5": categories.get("H5", ["", ""])[1] "jyFljH5": categories.get("H5", ["", ""])[1]
} }
elif template_type == 'aty': # aty模板
url_mapping = {
"atyApp": categories.get("全站", [""])[0] if categories.get("全站", [""]) else
categories.get("全站APP", [""])[0],
"atytyApp": categories.get("体育", [""])[0] if categories.get("体育", [""]) else
categories.get("体育APP", [""])[0],
"atyWeb": categories.get("WEB", [""])[0] if categories.get("WEB", [""]) else categories.get("web", [""])[
0],
"atyH5": categories.get("H5", [""])[0] if categories.get("H5", [""]) else categories.get("h5", [""])[0]
}
else: else:
print('未知模板') print('未知模板')
return return
@ -78,30 +88,52 @@ def get_url_mapping(urls_with_context, template_type):
def extract_urls(text): def extract_urls(text):
pattern = r'(?:\n|^)\s*([^\n]*?)\s*(https?://[^\s]+)' pattern = r'(?:\n|^)\s*([^\n]*?)\s*(https?://[^\s]+)'
# 查找到所有的url
url_type = 'unknown'
is_agent = False
url_list = re.findall(pattern, text) url_list = re.findall(pattern, text)
url_type, is_agent = get_url_type(text, url_list)
if url_type != 'unknown':
update_agent_url(url_list, url_type)
return [(context.strip(), url) for context, url in url_list], url_type, is_agent
def get_url_type(text, url_list):
keywords = {
'ky': '开云',
'hth': '华体会',
'jy': '九游',
'aty': '爱体育'
}
for url_type, keyword in keywords.items():
if keyword in text:
return url_type, False
return check_urls(url_list)
def check_urls(url_list):
headers = {
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'
}
for context, url in url_list: for context, url in url_list:
try: try:
response = requests.get(url, headers={ response = requests.get(url, headers=headers)
'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36'}) if response.status_code == 200:
if response.status_code == 200 or "开云" in text: content = response.text
if "开云" in response.text or ky_base64 in response.text or "开云" in text: if '开云' in content or ky_base64 in content:
url_type = 'ky' return 'ky', '马甲包' in content
elif '华体会' in response.text: elif '华体会' in content:
url_type = 'hth' return 'hth', '马甲包' in content
elif '九游' in response.text: elif '九游' in content:
url_type = 'jy' return 'jy', '马甲包' in content
# 判断是后台代理连接 elif '爱体育' in content:
if '马甲包' in response.text: return 'aty', '马甲包' in content
is_agent = True
if url_type != 'unknown':
update_agent_url(url_list, url_type)
break
except requests.RequestException: except requests.RequestException:
print(f"URL '{url}' 不可用,跳过。") print(f"URL '{url}' 不可用,跳过。")
return [(context.strip(), url) for context, url in url_list], url_type, is_agent
return 'unknown', False
def update_agent_url(url_list, url_type): def update_agent_url(url_list, url_type):
@ -112,25 +144,26 @@ def update_agent_url(url_list, url_type):
update_stmt = sql_text("UPDATE ky_tools.ky_account SET url = :url WHERE type = :url_type") update_stmt = sql_text("UPDATE ky_tools.ky_account SET url = :url WHERE type = :url_type")
connection.execute(update_stmt, {"url": url, "url_type": url_type}) connection.execute(update_stmt, {"url": url, "url_type": url_type})
connection.commit() connection.commit()
print(f"{url_type}后台链接更新成功")
except Exception as e: except Exception as e:
print(f"执行SQL语句出错: {e}") print(f"执行SQL语句出错: {e}")
break break
def update_js_content(url_mapping, url_type): def update_js_content(url_mapping, url_type):
js_file = 'template/link.js' js_file = 'link.js'
# 读取现有的 link.js 文件内容 # 读取现有的 link.js 文件内容
try: try:
with open(js_file, 'r') as file: existing_content = read_file(js_file)
existing_content = file.read()
except FileNotFoundError: except FileNotFoundError:
# 如果文件不存在,则创建一个新的 JavaScript 文件 # 如果文件不存在,则创建一个新的 JavaScript 文件
existing_content = """ existing_content = """
const codes = { const codes = {
'hth': '3016341', 'hth': '3016341',
'ky': '97238304', 'ky': '97238304',
'jy': '90413847' 'jy': '90413847',
'aty': '123456'
}; };
const links = { const links = {
@ -157,7 +190,13 @@ const links = {
'jyDz': 'https://www.3z9tsr.vip:9964/?i_code='+codes['jy'], 'jyDz': 'https://www.3z9tsr.vip:9964/?i_code='+codes['jy'],
'jyFljPc': 'https://www.az8z32.vip:8002/register/?i_code='+codes['jy'], 'jyFljPc': 'https://www.az8z32.vip:8002/register/?i_code='+codes['jy'],
'jyFljH5': 'https://www.c053i2.vip:6004/entry/register?i_code='+codes['jy'], 'jyFljH5': 'https://www.c053i2.vip:6004/entry/register?i_code='+codes['jy'],
} },
'aty': {
'atyWeb': 'https://www.3wmnr0.vip:8005/register?i_code='+codes['aty'],
'atyH5': 'https://www.95b8ns.vip:8002/entry/register?i_code='+codes['aty'],
'atyApp': 'https://www.jv4n7s1.com:8000/?i_code='+codes['aty'],
'atytyApp': 'https://www.cmqd0v.vip:9515/?i_code='+codes['aty'],
},
}; };
function visit(platform, key) { function visit(platform, key) {
window.open(links[platform][key]); window.open(links[platform][key]);
@ -165,17 +204,15 @@ function visit(platform, key) {
""" """
# 使用正则表达式匹配和替换链接的域名部分 # 使用正则表达式匹配和替换链接的域名部分
for key, value in url_mapping.items(): for key, value in url_mapping.items():
print(f"key: {key}, value: {value}") print(f"key: {key}, value: {value}")
pattern = re.compile(r"'{}':?\s*'(https?://[^/]+)(/[^']*)'".format(key)) pattern = re.compile(r"'{}':?\s*'(https?://[^/]+)(/[^']*)'".format(key))
existing_content = pattern.sub(lambda match: "'{0}': '{1}{2}'".format(key, value, match.group(2)), existing_content = pattern.sub(lambda match: "'{0}': '{1}{2}'".format(key, value, match.group(2)),
existing_content) existing_content)
# 将更新后的内容写回到 combined.js 文件中 # 将更新后的内容写回到 combined.js 文件中
with open(js_file, 'w') as file: write_file(js_file, existing_content)
file.write(existing_content)
def change_url(text): def change_url(text):
@ -197,20 +234,14 @@ def change_url(text):
if __name__ == '__main__': if __name__ == '__main__':
try: try:
text = ''' text = '''
九游娱乐 web https://www.buusiw9.vip:7443
SEO 专用域名 H5 https://www.rnygj7.vip:9443
全站APP https://www.csmbmex.vip:6004
WEB https://www.1wv3jq.com:9008 体育APP https://www.loo34.vip:6004
H5 https://www.1j5voy.vip:9113 代理web https://www.0rlnof1.com:8005
全站 https://www.shbb1.vip:9511   代理H5 https://www.1c1s9fr.com:9443
棋牌 https://www.3a10en.vip:9077
电子 https://www.3z9tsr.vip:9964
九游娱乐SEO防拦截域名
WEB https://www.az8z32.vip:8002
H5 https://www.c053i2.vip:6004
''' '''
change_url(text) change_url(text)
except Exception as e: except Exception as e:
print(f"An error occurred in the main program: {e}") print(f"An error occurred in the main program: {e}")