# -*- coding: utf-8 -*-
import os
import re
def clean_and_save(path, content):
content = content.replace('\r\n', '\n').replace('\r', '\n')
lines = [line.rstrip() for line in content.split('\n')]
result_lines = []
prev_empty = False
for line in lines:
if line == '':
if not prev_empty:
result_lines.append(line)
prev_empty = True
else:
result_lines.append(line)
prev_empty = False
while result_lines and result_lines[-1] == '':
result_lines.pop()
text = '\r\n'.join(result_lines) + '\r\n'
text = text.lstrip('\ufeff')
with open(path, 'wb') as f:
f.write(b'\xef\xbb\xbf' + text.encode('utf-8'))
def update_raid_lh4():
# 1. raids/index.html
path_idx = 'raids/index.html'
with open(path_idx, 'rb') as f:
c = f.read().decode('utf-8', errors='ignore')
if 'arcadia_lh4.html' not in c:
c = c.replace('\r\n', '\n')
target = '
攻略を見る ➜ | \n '
new_row = '''攻略を見る ➜ |
至天の座 アルカディア: ライトヘビー級4層 |
Lv100 (パッチ7.x最新) |
【最新ノーマルレイド】 ボス「ウィケッドサンダー」。ウィッチハント、エレクトロープ展開、床破壊。 |
攻略を見る ➜ |
'''
if target in c:
c = c.replace(target, new_row)
else:
c = re.sub(r'(.*? | \s*)', r'\1\n \n 至天の座 アルカディア: ライトヘビー級4層 | \n Lv100 (パッチ7.x最新) | \n 【最新ノーマルレイド】 ボス「ウィケッドサンダー」。ウィッチハント、エレクトロープ展開、床破壊。 | \n 攻略を見る ➜ | \n
', c)
clean_and_save(path_idx, c)
print("Updated raids/index.html")
# 2. common/sidebar.html
path_sb = 'common/sidebar.html'
with open(path_sb, 'rb') as f:
c = f.read().decode('utf-8', errors='ignore')
new_sb = 'アルカディア LH4層 (Lv100)'
if new_sb not in c:
c = c.replace('\r\n', '\n')
c = re.sub(r'(.*?)', r'\1\n ' + new_sb, c)
clean_and_save(path_sb, c)
print("Updated common/sidebar.html")
# 3. common/js/wiki_common.js
path_js = 'common/js/wiki_common.js'
with open(path_js, 'rb') as f:
c = f.read().decode('utf-8', errors='ignore')
new_js = "{ text: 'アルカディア LH4層 (Lv100)', path: 'raids/arcadia_lh4.html' }"
if 'arcadia_lh4.html' not in c:
c = c.replace('\r\n', '\n')
c = re.sub(r"(\{ text: 'アルカディア LH3層 \(Lv100\)', path: 'raids/arcadia_lh3\.html' \})", r"\1,\n " + new_js, c)
clean_and_save(path_js, c)
print("Updated common/js/wiki_common.js")
if __name__ == '__main__':
clean_and_save('raids/arcadia_lh4.html', open('raids/arcadia_lh4.html', 'r', encoding='utf-8', errors='ignore').read())
update_raid_lh4()