import re def rewrite_script(): with open('/root/.hermes/profiles/reviewer/scripts/top_heroes_tracker.py', 'r') as f: content = f.read() # Fix PocketGamer parser pg_old = """ idx_pg_exp = html_pg.find("Expired") if idx_pg_exp != -1: exp_block = html_pg[idx_pg_exp:idx_pg_exp+4000] clean_exp = re.sub('<[^<]+?>', ' ', exp_block) for word in clean_exp.split(): clean_w = clean_code_string(word) if is_valid_code_format(clean_w): all_expired.add(clean_w)""" pg_new = """ idx_pg_exp = html_pg.find("Expired") if idx_pg_exp != -1: exp_block = html_pg[idx_pg_exp:idx_pg_exp+4000] codes = re.findall(r'([A-Za-z0-9]{5,20})', re.sub(r'<[^>]+>', ' ', exp_block)) for clean_w in codes: if is_valid_code_format(clean_w) and not clean_w.islower() and sum(1 for c in clean_w if c.isupper()) > 1: all_expired.add(clean_w)""" content = content.replace(pg_old, pg_new) pg_act_old = """ clean_act = re.sub('<[^<]+?>', ' ', act_block) for word in clean_act.split(): clean_w = clean_code_string(word) if is_valid_code_format(clean_w) and clean_w not in all_expired: if clean_w not in stage_active: stage_active[clean_w] = "Mã quà tặng từ PocketGamer\"""" pg_act_new = """ codes = re.findall(r'([A-Za-z0-9]{5,20})[<\\s]', act_block) for clean_w in codes: if is_valid_code_format(clean_w) and clean_w not in all_expired: if clean_w not in stage_active: stage_active[clean_w] = "Mã quà tặng từ PocketGamer\"""" content = content.replace(pg_act_old, pg_act_new) # Fix GameRant parser gr_old = """ idx_exp = html_gamerant.find("Expired Top Heroes Codes") if idx_exp != -1: exp_block = html_gamerant[idx_exp:idx_exp+4000] clean_exp = re.sub('<[^<]+?>', ' ', exp_block) for word in clean_exp.split(): clean_w = clean_code_string(word) if is_valid_code_format(clean_w): all_expired.add(clean_w)""" gr_new = """ idx_exp = html_gamerant.find("Expired Top Heroes Codes") if idx_exp != -1: exp_block = html_gamerant[idx_exp:idx_exp+4000] codes = re.findall(r'
  • \\s*([A-Za-z0-9]{5,20})', exp_block) for clean_w in codes: if is_valid_code_format(clean_w): all_expired.add(clean_w)""" content = content.replace(gr_old, gr_new) gr_act_old = """ clean_act = re.sub('<[^<]+?>', ' ', act_block) for word in clean_act.split(): clean_w = clean_code_string(word) if is_valid_code_format(clean_w) and clean_w not in all_expired: if clean_w not in stage_active: stage_active[clean_w] = "Mã quà tặng từ GameRant\"""" gr_act_new = """ codes = re.findall(r'
  • \\s*([A-Za-z0-9]{5,20})', act_block) for clean_w in codes: if is_valid_code_format(clean_w) and clean_w not in all_expired: if clean_w not in stage_active: stage_active[clean_w] = "Mã quà tặng từ GameRant\"""" content = content.replace(gr_act_old, gr_act_new) # Enhance is_valid_code_format to reject pure english words (lowercased) valid_old = """ if not re.match(r'^[A-Za-z0-9]+$', s): return False if s.isalpha() and len(s) >= 4 and s.lower() in (""" valid_new = """ if not re.match(r'^[A-Za-z0-9]+$', s): return False # Reject if purely lowercase or purely camelCase english words (heuristic) if s.isalpha() and s.islower(): return False if s.isalpha() and len(s) >= 4 and s.lower() in (""" content = content.replace(valid_old, valid_new) # Change sorting: sort_old = """ def sort_key(item): st = item[1]["status"] priority = 0 if st == "permanent" else (1 if st == "active" else 2) return (priority, item[0])""" sort_new = """ def sort_key(item): st = item[1]["status"] # Alphabetical by status, but expired ALWAYS at the end if st.lower() == "expired": priority = 999 else: priority = 1 return (priority, st, item[0])""" content = content.replace(sort_old, sort_new) with open('/root/.hermes/profiles/reviewer/scripts/top_heroes_tracker.py', 'w') as f: f.write(content) print("Rewrote script") rewrite_script()