chore: リンク更新用スクリプトツールのコミット
This commit is contained in:
1 parent
cf35adc48d
commit
a653dcb5a6
122 files changed
+5826
No files matched your search
@@ -0,0 +1,50 @@
|
||||
# -*- 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="byakko.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 byakko")
|
||||
else:
|
||||
print("Failed to find target row in trials/index.html")
|
||||
|
||||
normalize_file('trials/index.html')
|
||||
normalize_file('trials/byakko.html')
|
||||
Reference in new issue
Block a user