51 lines
1.6 KiB
Python
51 lines
1.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
import os
|
|
import sys
|
|
|
|
def normalize_file(filepath):
|
|
with open(filepath, 'rb') as f:
|
|
raw = f.read()
|
|
content = raw.decode('utf-8', errors='replace').lstrip('\ufeff')
|
|
content = content.replace('\r\n', '\n').replace('\r', '\n')
|
|
lines = [line.rstrip(' \t') for line in content.split('\n')]
|
|
cleaned_lines = []
|
|
prev_empty = False
|
|
for line in lines:
|
|
if line == '':
|
|
if not prev_empty:
|
|
cleaned_lines.append(line)
|
|
prev_empty = True
|
|
else:
|
|
cleaned_lines.append(line)
|
|
prev_empty = False
|
|
new_content = '\r\n'.join(cleaned_lines)
|
|
with open(filepath, 'wb') as f:
|
|
f.write(b'\xef\xbb\xbf' + new_content.encode('utf-8'))
|
|
print(f"Normalized: {filepath}")
|
|
|
|
index_path = 'trials/index.html'
|
|
with open(index_path, 'r', encoding='utf-8') as f:
|
|
lines = f.readlines()
|
|
|
|
updated = False
|
|
for i, line in enumerate(lines):
|
|
if 'リオレウス狩猟戦 / 極リオレウス' in line:
|
|
for k in range(i, i+6):
|
|
if '<td>準備中</td>' in lines[k]:
|
|
lines[k] = lines[k].replace('<td>準備中</td>', '<td><a href="rathalos.html">攻略を見る ➜</a></td>')
|
|
updated = True
|
|
print(f"Replaced line {k+1}")
|
|
break
|
|
if updated:
|
|
break
|
|
|
|
if updated:
|
|
with open(index_path, 'w', encoding='utf-8') as f:
|
|
f.writelines(lines)
|
|
print("Successfully updated trials/index.html for rathalos")
|
|
else:
|
|
print("Failed to find target row in trials/index.html")
|
|
|
|
normalize_file('trials/index.html')
|
|
normalize_file('trials/rathalos.html')
|