mirror of
https://github.com/LmeSzinc/AzurLaneAutoScript.git
synced 2025-01-08 12:07:36 +08:00
Add: auto format for campaign/Readme.md
This commit is contained in:
parent
98e6d1397c
commit
049f478fd5
@ -216,4 +216,4 @@ To add a new event, add a new row in here, and run `python -m module.config.conf
|
||||
| 20240912 | event 20240912 cn | Ode of Everblooming Crimson | 唤醒苍红之炎 | Ode of Everblooming Crimson | 絳染む丹華の詠歌 | - |
|
||||
| 20240919 | event 20230914 cn | Effulgence Before Eclipse | - | - | - | 須臾望月抄 |
|
||||
| 20241017 | event 20220728 cn | Aquilifer's Ballade Rerun | 复刻雄鹰的叙事歌 | Aquilifer's Ballade Rerun | 鋼鷲の冒険譚(復刻) | - |
|
||||
| 20241017 | coalition 20240627 | Welcome to Little Academy | - | - | - | 歡迎來到童心學院 |
|
||||
| 20241017 | coalition 20240627 | Welcome to Little Academy | - | - | - | 歡迎來到童心學院 |
|
||||
|
@ -382,13 +382,38 @@ class ConfigGenerator:
|
||||
Returns:
|
||||
list[Event]: From latest to oldest
|
||||
"""
|
||||
def calc_width(text):
|
||||
return len(text) + len(re.findall(
|
||||
r'[\u3000-\u30ff\u3400-\u4dbf\u4e00-\u9fff、!()]', text))
|
||||
|
||||
lines = []
|
||||
data_lines = []
|
||||
data_widths = []
|
||||
column_width = [4]*7 # `:---`
|
||||
events = []
|
||||
with open('./campaign/Readme.md', encoding='utf-8') as f:
|
||||
for text in f.readlines():
|
||||
if re.search(r'\d{8}', text):
|
||||
event = Event(text)
|
||||
events.append(event)
|
||||
|
||||
if not re.search(r'^\|.+\|$', text):
|
||||
# not a table line
|
||||
lines.append(text)
|
||||
elif re.search(r'^.*\-{3,}.*$', text):
|
||||
# is a delimiter line
|
||||
continue
|
||||
else:
|
||||
line_entries = [x.strip() for x in text.strip('| \n').split('|')]
|
||||
data_lines.append(line_entries)
|
||||
data_width = [calc_width(string) for string in line_entries]
|
||||
data_widths.append(data_width)
|
||||
column_width = [max(l1, l2) for l1, l2 in zip(column_width, data_width)]
|
||||
if re.search(r'\d{8}', text):
|
||||
event = Event(text)
|
||||
events.append(event)
|
||||
for i, (line, old_width) in enumerate(zip(data_lines, data_widths)):
|
||||
lines.append('| ' + ' | '.join([cell+' '*(width-length) for cell, width, length in zip(line, column_width, old_width)]) + ' |\n')
|
||||
if i == 0:
|
||||
lines.append('| ' + ' | '.join([':'+'-'*(width-1) for width in column_width]) + ' |\n')
|
||||
with open('./campaign/Readme.md', 'w', encoding='utf-8') as f:
|
||||
f.writelines(lines)
|
||||
return events[::-1]
|
||||
|
||||
def insert_event(self):
|
||||
|
Loading…
Reference in New Issue
Block a user