diff --git a/src/change_url/change_url.py b/src/change_url/change_url.py index 1ff9a3b..51b0ef2 100644 --- a/src/change_url/change_url.py +++ b/src/change_url/change_url.py @@ -1,5 +1,9 @@ import re +hth_keywords = ["华体会", "hth", "HTH"] +ky_keywords = ["开云"] +jy_keywords = ["九游"] + def read_file(filename): try: @@ -26,11 +30,9 @@ def replace_urls(js_content, url_mapping): def get_url_mapping(urls_with_context, is_seo, template_type): - categories = {} - # 初始化categories字典,区分SEO和非SEO模式 - if is_seo or template_type == 'ky': - categories = {"WEB": [], "H5": [], "全站": [], "体育": []} + if is_seo or template_type == 'ky' or template_type == 'jy': + categories = {"WEB": [], "H5": [], "全站": [], "体育": [], "棋牌": [], "电子": []} else: # 非SEO模式下的hth模板 categories = {"web": [], "h5": [], "全站APP": [], "体育APP": []} @@ -48,46 +50,65 @@ def get_url_mapping(urls_with_context, is_seo, template_type): "{{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] } - else: # ky模板 + elif template_type == 'ky': # ky模板 url_mapping = { "{{kyPc1}}": categories.get("WEB", [""])[0], "{{kyPc2}}": categories.get("WEB", ["", ""])[1], "{{kyH51}}": categories.get("H5", [""])[0], "{{kyH52}}": categories.get("H5", ["", ""])[1], "{{kyApp1}}": categories.get("全站", [""])[0], - "{{kyApp2}}": categories.get("全站", ["", ""])[1], + "{{kyApp2}}": categories.get("体育", [""])[0], + # "{{kyApp2}}": categories.get("全站", ["", ""])[1], "{{kyTy1}}": categories.get("体育", [""])[0], - "{{kyTy2}}": categories.get("体育", ["", ""])[1] + "{{kyTy2}}": categories.get("全站", [""])[0], + # "{{kyTy2}}": categories.get("体育", ["", ""])[1] } + elif template_type == 'jy': # jy模板 + url_mapping = { + "{{jyPc}}": categories.get("WEB", [""])[0], + "{{jyH5}}": categories.get("H5", [""])[0], + "{{jyApp}}": categories.get("全站", [""])[0], + "{{jyQp}}": categories.get("棋牌", [""])[0], + "{{jyDz}}": categories.get("电子", [""])[0], + "{{jyFljPc}}": categories.get("WEB", [""])[1], + "{{jyFljH5}}": categories.get("H5", [""])[1], + } + else: + print('未知模板') + return return url_mapping def extract_urls(text): - seo_part_index = text.find("SEO 防拦截域名") - relevant_text = text[:seo_part_index] if seo_part_index != -1 else text + # seo_part_index = text.find("SEO 防拦截域名") + # relevant_text = text[:seo_part_index] if seo_part_index != -1 else text pattern = r'(?:\n|^)\s*([^\n]*?)\s*(https?://[^\s]+)' - matches = re.findall(pattern, relevant_text) + matches = re.findall(pattern, text) return [(context.strip(), url) for context, url in matches] def change_url(text, hth_template_path='/www/wwwroot/change_url/hth.js.template', - ky_template_path='/www/wwwroot/change_url/ky.js.template'): + ky_template_path='/www/wwwroot/change_url/ky.js.template', + jy_template_path='/www/wwwroot/change_url/jy.js.template'): try: urls_with_context = extract_urls(text) expected_filename = None - - if '代理' in text: + # 如果字符中有代理,则带后台链接 + if '代理WEB' in text or '代理web' in text: is_seo = False else: is_seo = True - if len(urls_with_context) in [4, 6]: + if any(keyword in text for keyword in hth_keywords) or not is_seo: template_path = hth_template_path template_type = 'hth' - elif len(urls_with_context) == 8: + elif any(keyword in text for keyword in ky_keywords): template_path = ky_template_path template_type = 'ky' + elif any(keyword in text for keyword in jy_keywords): + template_path = jy_template_path + template_type = 'jy' else: return False, 'unknown.js' @@ -101,3 +122,17 @@ def change_url(text, hth_template_path='/www/wwwroot/change_url/hth.js.template' except Exception as e: print(f"An error occurred: {e}") return False, expected_filename if expected_filename else 'unknown.js' + +if __name__ == '__main__': + 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''' + 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 diff --git a/src/change_url/template/hth.js.template b/src/change_url/template/hth.js.template new file mode 100644 index 0000000..8223739 --- /dev/null +++ b/src/change_url/template/hth.js.template @@ -0,0 +1,12 @@ +const hthCode = '3016341' + +var hth_link = { + hthApp: '{{hthApp}}/?i_code='+hthCode, + hthtyApp: '{{hthtyApp}}/?i_code='+hthCode, + hthPc: '{{hthPc}}/register/?i_code='+hthCode, + hthH5: '{{hthH5}}/entry/register?i_code='+hthCode, +} + +function visit_hth(key) { + window['open'](hth_link[key]); +} \ No newline at end of file diff --git a/src/change_url/template/jy.js.template b/src/change_url/template/jy.js.template new file mode 100644 index 0000000..5e58299 --- /dev/null +++ b/src/change_url/template/jy.js.template @@ -0,0 +1,16 @@ +const jyCode = '90413847' + +var jy_link = { + jyPc: '{{jyPc}}/register/?i_code='+jyCode, + jyH5: '{{jyH5}}/entry/register?i_code='+jyCode, + jyApp: '{{jyApp}}/?i_code='+jyCode, + jyQp:'{{jyQp}}/?i_code='+jyCode, + jyDz:'{{jyDz}}/?i_code='+jyCode, + jyFljPc:'{{jyFljPc}}/?i_code='+jyCode, + jyFljH5:'{{jyFljH5}}/?i_code='+jyCode, +} + + +function visit_jy(key) { + window['open'](jy_link[key]); +} \ No newline at end of file diff --git a/src/change_url/template/ky.js.template b/src/change_url/template/ky.js.template new file mode 100644 index 0000000..f93c38a --- /dev/null +++ b/src/change_url/template/ky.js.template @@ -0,0 +1,15 @@ +const kyCode = '97238304' + +var ky_link = { + kyApp1: '{{kyApp1}}/?i_code='+kyCode, + kyApp2: '{{kyApp2}}/?i_code='+kyCode, + kyPc1: '{{kyPc1}}/register/?i_code='+kyCode, + kyPc2: '{{kyPc2}}/register?i_code='+kyCode, + kyH51: '{{kyH51}}/entry/register?i_code='+kyCode, + kyH52: '{{kyH52}}/entry/register?i_code='+kyCode +} + + +function visit_ky(key) { + window['open'](ky_link[key]); +} \ No newline at end of file