From efbcc9c0453b950ce933d236731a5a8210cac15d Mon Sep 17 00:00:00 2001 From: zayac Date: Wed, 27 Mar 2024 17:49:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99=E7=9A=84?= =?UTF-8?q?=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/change_url/change_url.py | 49 ++++++++++++++---------------------- 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/src/change_url/change_url.py b/src/change_url/change_url.py index 51b0ef2..12152b9 100644 --- a/src/change_url/change_url.py +++ b/src/change_url/change_url.py @@ -1,6 +1,6 @@ import re -hth_keywords = ["华体会", "hth", "HTH"] +hth_keywords = ["华体会", "hth", "HTH", "代理WEB"] ky_keywords = ["开云"] jy_keywords = ["九游"] @@ -29,13 +29,8 @@ def replace_urls(js_content, url_mapping): return js_content -def get_url_mapping(urls_with_context, is_seo, template_type): - # 初始化categories字典,区分SEO和非SEO模式 - if is_seo or template_type == 'ky' or template_type == 'jy': - categories = {"WEB": [], "H5": [], "全站": [], "体育": [], "棋牌": [], "电子": []} - else: # 非SEO模式下的hth模板 - categories = {"web": [], "h5": [], "全站APP": [], "体育APP": []} - +def get_url_mapping(urls_with_context, template_type): + categories = {"WEB": [], "H5": [], "全站": [], "体育": [], "棋牌": [], "电子": [],"web": [], "h5": [], "全站APP": [], "体育APP": []} # 遍历URLs及其前文本的元组列表进行分类 for context, url in urls_with_context: key = context.strip().replace(" ", "") @@ -45,10 +40,10 @@ def get_url_mapping(urls_with_context, is_seo, template_type): # 构建映射字典,直接返回结果 if template_type == 'hth': url_mapping = { - "{{hthApp}}": categories.get("全站", [""])[0] if is_seo else categories.get("全站APP", [""])[0], - "{{hthtyApp}}": categories.get("体育", [""])[0] if is_seo else categories.get("体育APP", [""])[0], - "{{hthPc}}": categories.get("WEB", [""])[0] if is_seo else categories.get("web", [""])[0], - "{{hthH5}}": categories.get("H5", [""])[0] if is_seo else categories.get("h5", [""])[0] + "{{hthApp}}": categories.get("全站", [""])[0] if categories.get("全站", [""])[0] else categories.get("全站APP", [""])[0], + "{{hthtyApp}}": categories.get("体育", [""])[0] if categories.get("体育", [""])[0] else categories.get("体育APP", [""])[0], + "{{hthPc}}": categories.get("WEB", [""])[0] if categories.get("WEB", [""])[0] else categories.get("web", [""])[0], + "{{hthH5}}": categories.get("H5", [""])[0] if categories.get("H5", [""])[0] else categories.get("h5", [""])[0] } elif template_type == 'ky': # ky模板 url_mapping = { @@ -94,13 +89,7 @@ def change_url(text, hth_template_path='/www/wwwroot/change_url/hth.js.template' try: urls_with_context = extract_urls(text) expected_filename = None - # 如果字符中有代理,则带后台链接 - if '代理WEB' in text or '代理web' in text: - is_seo = False - else: - is_seo = True - - if any(keyword in text for keyword in hth_keywords) or not is_seo: + if any(keyword in text for keyword in hth_keywords): template_path = hth_template_path template_type = 'hth' elif any(keyword in text for keyword in ky_keywords): @@ -113,7 +102,7 @@ def change_url(text, hth_template_path='/www/wwwroot/change_url/hth.js.template' return False, 'unknown.js' js_content = read_file(template_path) - url_mapping = get_url_mapping(urls_with_context, is_seo, template_type) + url_mapping = get_url_mapping(urls_with_context, template_type) updated_content = replace_urls(js_content, url_mapping) expected_filename = template_path.replace('.template', '') write_file(expected_filename, updated_content) @@ -124,15 +113,15 @@ def change_url(text, hth_template_path='/www/wwwroot/change_url/hth.js.template' return False, expected_filename if expected_filename else 'unknown.js' if __name__ == '__main__': - text = '''SEO— 代理 专用域名 + text = '''华体会 +SEO专用域名 -WEB https://www.04qm83.vip:6004 -H5 https://www.17wq4x.vip:9520 【新】 -全站 https://www.abucqv.com:9519 【新】 -棋牌 https://www.2ghc85.vip:8004 【新】 -电子 https://www.3mczux.vip:6001 【新】 - -九游娱乐【SEO防拦截域名】 -WEB https://www.9ji5rw.com:9519 -H5 https://www.9myqr9.com:9502''' +WEB  https://www.cww2mcl.com:8002 +H5 https://www.gauo9k.com:6443 +全站 https://www.9qhjyb.vip:9505 +体育 https://www.cjmn0b.vip:9020    【新】 + +SEO 防拦截域名 +WEB https://www.wyr8s.com:9663 +H5 https://www.ow9860n.com:9663''' change_url(text,hth_template_path='template/hth.js.template',ky_template_path='template/ky.js.template',jy_template_path='template/jy.js.template') \ No newline at end of file