diff --git a/src/change_url/change_url.py b/src/change_url/change_url.py index cd2d113..d89e49c 100644 --- a/src/change_url/change_url.py +++ b/src/change_url/change_url.py @@ -69,6 +69,16 @@ def get_url_mapping(urls_with_context, template_type): "jyFljPc": categories.get("WEB", ["", ""])[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: print('未知模板') return @@ -78,30 +88,52 @@ def get_url_mapping(urls_with_context, template_type): def extract_urls(text): pattern = r'(?:\n|^)\s*([^\n]*?)\s*(https?://[^\s]+)' - # 查找到所有的url - url_type = 'unknown' - is_agent = False 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: try: - response = requests.get(url, 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 or "开云" in text: - if "开云" in response.text or ky_base64 in response.text or "开云" in text: - url_type = 'ky' - elif '华体会' in response.text: - url_type = 'hth' - elif '九游' in response.text: - url_type = 'jy' - # 判断是后台代理连接 - if '马甲包' in response.text: - is_agent = True - if url_type != 'unknown': - update_agent_url(url_list, url_type) - break + response = requests.get(url, headers=headers) + if response.status_code == 200: + content = response.text + if '开云' in content or ky_base64 in content: + return 'ky', '马甲包' in content + elif '华体会' in content: + return 'hth', '马甲包' in content + elif '九游' in content: + return 'jy', '马甲包' in content + elif '爱体育' in content: + return 'aty', '马甲包' in content except requests.RequestException: 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): @@ -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") connection.execute(update_stmt, {"url": url, "url_type": url_type}) connection.commit() + print(f"{url_type}后台链接更新成功") except Exception as e: print(f"执行SQL语句出错: {e}") break def update_js_content(url_mapping, url_type): - js_file = 'template/link.js' + js_file = 'link.js' # 读取现有的 link.js 文件内容 try: - with open(js_file, 'r') as file: - existing_content = file.read() + existing_content = read_file(js_file) except FileNotFoundError: # 如果文件不存在,则创建一个新的 JavaScript 文件 existing_content = """ const codes = { 'hth': '3016341', 'ky': '97238304', - 'jy': '90413847' + 'jy': '90413847', + 'aty': '123456' }; const links = { @@ -157,7 +190,13 @@ const links = { 'jyDz': 'https://www.3z9tsr.vip:9964/?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'], - } + }, + '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) { window.open(links[platform][key]); @@ -165,17 +204,15 @@ function visit(platform, key) { """ - # 使用正则表达式匹配和替换链接的域名部分 + # 使用正则表达式匹配和替换链接的域名部分 for key, value in url_mapping.items(): print(f"key: {key}, value: {value}") 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) - # 将更新后的内容写回到 combined.js 文件中 - with open(js_file, 'w') as file: - file.write(existing_content) + write_file(js_file, existing_content) def change_url(text): @@ -197,20 +234,14 @@ def change_url(text): if __name__ == '__main__': try: text = ''' -九游娱乐 -SEO 专用域名 - -WEB https://www.1wv3jq.com:9008 【新】 -H5 https://www.1j5voy.vip:9113 【新】 -全站 https://www.shbb1.vip:9511   【新】 -棋牌 https://www.3a10en.vip:9077 【新】 -电子 https://www.3z9tsr.vip:9964 【新】 - -九游娱乐【SEO防拦截域名】 -WEB https://www.az8z32.vip:8002 【新】 -H5 https://www.c053i2.vip:6004 【新】 +web https://www.buusiw9.vip:7443 【新】 +H5 https://www.rnygj7.vip:9443 +全站APP https://www.csmbmex.vip:6004 +体育APP https://www.loo34.vip:6004 +代理web https://www.0rlnof1.com:8005 【新】 +代理H5 https://www.1c1s9fr.com:9443 【新】 ''' change_url(text) except Exception as e: - print(f"An error occurred in the main program: {e}") + print(f"An error occurred in the main program: {e}") \ No newline at end of file