# -*- 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_tender_valley():
# 1. dungeons/index.html
path_idx = 'dungeons/index.html'
with open(path_idx, 'rb') as f:
c = f.read().decode('utf-8', errors='ignore')
if 'href="tender_valley.html"' not in c:
c = c.replace('
荒野秘境 サボテンダーバレー | \r\n\r\n Lv100 (IL690〜) | \r\n\r\n 黄金サブクエスト開放ID。砂漠と遺跡を舞台にした最新高難易度エキスパートID。 | \r\n\r\n 攻略を見る ➜ | ',
'荒野秘境 サボテンダーバレー | \r\n Lv100 (IL690〜) | \r\n 黄金サブクエスト開放ID。砂漠と遺跡を舞台にした最新高難易度エキスパートID。 | \r\n 攻略を見る ➜ | ')
c = c.replace('荒野秘境 サボテンダーバレー | \n\n Lv100 (IL690〜) | \n\n 黄金サブクエスト開放ID。砂漠と遺跡を舞台にした最新高難易度エキスパートID。 | \n\n 攻略を見る ➜ | ',
'荒野秘境 サボテンダーバレー | \n Lv100 (IL690〜) | \n 黄金サブクエスト開放ID。砂漠と遺跡を舞台にした最新高難易度エキスパートID。 | \n 攻略を見る ➜ | ')
c = re.sub(r'(サボテンダーバレー.*?)', r'\1', c, flags=re.DOTALL)
clean_and_save(path_idx, c)
print("Updated tender_valley in dungeons/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 = 'サボテンダーバレー (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("Added tender_valley to 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: 'サボテンダーバレー (Lv100)', path: 'dungeons/tender_valley.html' }"
if 'tender_valley.html' not in c:
c = c.replace('\r\n', '\n')
c = re.sub(r"(\{ text: '記憶幻想 アレクサンドリア \(Lv100\)', path: 'dungeons/alexandria\.html' \})", r"\1,\n " + new_js, c)
clean_and_save(path_js, c)
print("Added tender_valley to common/js/wiki_common.js")
if __name__ == '__main__':
clean_and_save('dungeons/tender_valley.html', open('dungeons/tender_valley.html', 'r', encoding='utf-8', errors='ignore').read())
update_tender_valley()
|