big tabs vs spaces adjust
This commit is contained in:
parent
b83bfe5687
commit
1f2c44c82d
268
build.py
268
build.py
|
@ -18,190 +18,194 @@ DELIMITER = "| :|"
|
||||||
# split strings longer than length into a list
|
# split strings longer than length into a list
|
||||||
# strings are split at last index of delim
|
# strings are split at last index of delim
|
||||||
def split_to_list(str, length, delim=' '):
|
def split_to_list(str, length, delim=' '):
|
||||||
l = []
|
l = []
|
||||||
|
|
||||||
while len(str) > length:
|
while len(str) > length:
|
||||||
sep = str.rfind(delim, 0, length)
|
sep = str.rfind(delim, 0, length)
|
||||||
l.append(str[0:sep])
|
l.append(str[0:sep])
|
||||||
str = str[sep+1:]
|
str = str[sep+1:]
|
||||||
|
|
||||||
l.append(str)
|
l.append(str)
|
||||||
|
|
||||||
return l
|
return l
|
||||||
|
|
||||||
# build_header using section title
|
# build_header using section title
|
||||||
def build_header(l_title):
|
def build_header(l_title, add_index=false, index_prefix=None):
|
||||||
header = []
|
header = []
|
||||||
|
|
||||||
len_title = len(l_title[0])
|
len_title = len(l_title[0])
|
||||||
pad, pad_left = divmod(MAX_WIDTH - (len_title + (TITLE_PADDING * 2)) - 2, 2)
|
pad, pad_left = divmod(MAX_WIDTH - (len_title + (TITLE_PADDING * 2)) - 2, 2)
|
||||||
len_border = len_title + ((TITLE_PADDING * 2) - 2)
|
len_border = len_title + ((TITLE_PADDING * 2) - 2)
|
||||||
|
|
||||||
# upper part
|
# upper part
|
||||||
header.append(' ' * (pad + pad_left + 2) + '_' * len_border + ' ' * (pad + 2))
|
header.append(' ' * (pad + pad_left + 2) + '_' * len_border + ' ' * (pad + 2))
|
||||||
header.append('_' * (pad + pad_left) + '//' + ' ' * len_border + '\\\\' + '_' * pad)
|
header.append('_' * (pad + pad_left) + '//' + ' ' * len_border + '\\\\' + '_' * pad)
|
||||||
# ' ' padded Title
|
# ' ' padded Title
|
||||||
count = 1
|
count = 1
|
||||||
for title in l_title:
|
for title in l_title:
|
||||||
c_pad = '_' if count == len(l_title) else ' '
|
c_pad = '_' if count == len(l_title) else ' '
|
||||||
pad_right = len_title - len(title)
|
pad_right = len_title - len(title)
|
||||||
header.append(c_pad * (pad + pad_left) + '|' + ' ' * TITLE_PADDING + title + ' ' * (TITLE_PADDING + pad_right) + '|' + c_pad * pad)
|
header.append(c_pad * (pad + pad_left) + '|' + ' ' * TITLE_PADDING + title + ' ' * (TITLE_PADDING + pad_right) + '|' + c_pad * pad)
|
||||||
count += 1
|
count += 1
|
||||||
# lower part
|
# lower part
|
||||||
header.append(' ' * (pad + pad_left) + '\\\\' + '_' * len_border + '//' + ' ' * pad)
|
header.append(' ' * (pad + pad_left) + '\\\\' + '_' * len_border + '//' + ' ' * pad)
|
||||||
header.append(' ' * MAX_WIDTH)
|
# add navigation tag
|
||||||
|
if add_index == true and index_prefix.length == 1:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
header.append(' ' * MAX_WIDTH)
|
||||||
|
|
||||||
return header
|
return header
|
||||||
|
|
||||||
def build_index(yaml, prefix):
|
def build_index(yaml, prefix):
|
||||||
l_title = []
|
l_title = []
|
||||||
for item in yaml:
|
for item in yaml:
|
||||||
l_title += [item['title']]
|
l_title += [item['title']]
|
||||||
|
|
||||||
l_index = []
|
l_index = []
|
||||||
for i, item in enumerate(l_title):
|
for i, item in enumerate(l_title):
|
||||||
l_index += [' - ' + item.ljust(MAX_WIDTH - 10) + f'[{prefix}{i+1:03}] ']
|
l_index += [' - ' + item.ljust(MAX_WIDTH - 10) + f'[{prefix}{i+1:03}] ']
|
||||||
|
|
||||||
l_index += [' ' * MAX_WIDTH]
|
l_index += [' ' * MAX_WIDTH]
|
||||||
|
|
||||||
return l_index
|
return l_index
|
||||||
|
|
||||||
def build_game(name, platform):
|
def build_game(name, platform):
|
||||||
s_platform = platform.ljust(MAX_WIDTH_PLATFORM)
|
s_platform = platform.ljust(MAX_WIDTH_PLATFORM)
|
||||||
s_name = name.ljust(MAX_WIDTH_NAME)
|
s_name = name.ljust(MAX_WIDTH_NAME)
|
||||||
|
|
||||||
return f' {s_platform} | {s_name} '
|
return f' {s_platform} | {s_name} '
|
||||||
|
|
||||||
#
|
#
|
||||||
# main
|
# main
|
||||||
#
|
#
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
print('go')
|
print('go')
|
||||||
with open(f'{BASE}/todo.yaml', 'r') as file:
|
with open(f'{BASE}/todo.yaml', 'r') as file:
|
||||||
todo_yaml = yaml.safe_load(file)
|
todo_yaml = yaml.safe_load(file)
|
||||||
|
|
||||||
with open(f'{BASE}/finished.yaml', 'r') as file:
|
with open(f'{BASE}/finished.yaml', 'r') as file:
|
||||||
finished_yaml = yaml.safe_load(file)
|
finished_yaml = yaml.safe_load(file)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Section: TO-DO
|
# Section: TO-DO
|
||||||
#
|
#
|
||||||
|
|
||||||
todo_result = []
|
todo_result = []
|
||||||
|
|
||||||
todo_result += build_header([TITLE_LEFT])
|
todo_result += build_header([TITLE_LEFT])
|
||||||
|
|
||||||
todo_result += build_index(todo_yaml, 'S')
|
todo_result += build_index(todo_yaml, 'S')
|
||||||
|
|
||||||
for section in todo_yaml:
|
for section in todo_yaml:
|
||||||
s_title = section['title']
|
s_title = section['title']
|
||||||
l_title = []
|
l_title = []
|
||||||
|
|
||||||
if len(s_title) > MAX_WIDTH_TITLE:
|
if len(s_title) > MAX_WIDTH_TITLE:
|
||||||
l_title = split_to_list(s_title, MAX_WIDTH_TITLE)
|
l_title = split_to_list(s_title, MAX_WIDTH_TITLE)
|
||||||
else:
|
else:
|
||||||
l_title = [s_title]
|
l_title = [s_title]
|
||||||
|
|
||||||
# Create section header
|
# Create section header
|
||||||
todo_result += build_header(l_title)
|
todo_result += build_header(l_title)
|
||||||
|
|
||||||
# Create table header
|
# Create table header
|
||||||
todo_result += [' ______ ________________________________________________________',
|
todo_result += [' ______ ________________________________________________________',
|
||||||
'|======|========================================================']
|
'|======|========================================================']
|
||||||
|
|
||||||
# Add games one by one
|
# Add games one by one
|
||||||
# Prefix : |
|
# Prefix : |
|
||||||
for game in section['games']:
|
for game in section['games']:
|
||||||
s_name = game['name']
|
s_name = game['name']
|
||||||
s_platform = game['platform']
|
s_platform = game['platform']
|
||||||
|
|
||||||
if len(s_platform) > MAX_WIDTH_PLATFORM:
|
if len(s_platform) > MAX_WIDTH_PLATFORM:
|
||||||
raise Exception(f"Platform shortcode for {s_name} is longer than 4 characters. Cannot parse...")
|
raise Exception(f"Platform shortcode for {s_name} is longer than 4 characters. Cannot parse...")
|
||||||
|
|
||||||
if len(s_name) > MAX_WIDTH_NAME:
|
if len(s_name) > MAX_WIDTH_NAME:
|
||||||
l_name = split_to_list(s_name, MAX_WIDTH_NAME)
|
l_name = split_to_list(s_name, MAX_WIDTH_NAME)
|
||||||
for i,i_name in enumerate(l_name):
|
for i,i_name in enumerate(l_name):
|
||||||
todo_result += ['|' + build_game(i_name, s_platform if i == 0 else '')]
|
todo_result += ['|' + build_game(i_name, s_platform if i == 0 else '')]
|
||||||
else:
|
else:
|
||||||
todo_result += ['|' + build_game(s_name, s_platform)]
|
todo_result += ['|' + build_game(s_name, s_platform)]
|
||||||
|
|
||||||
# Close table header
|
# Close table header
|
||||||
todo_result += ['|______|________________________________________________________',
|
todo_result += ['|______|________________________________________________________',
|
||||||
' ' * MAX_WIDTH]
|
' ' * MAX_WIDTH]
|
||||||
|
|
||||||
#
|
#
|
||||||
# Section: Finished
|
# Section: Finished
|
||||||
#
|
#
|
||||||
|
|
||||||
finished_result = []
|
finished_result = []
|
||||||
|
|
||||||
finished_result += build_header([TITLE_RIGHT])
|
finished_result += build_header([TITLE_RIGHT])
|
||||||
|
|
||||||
finished_result += build_index(finished_yaml, 'P')
|
finished_result += build_index(finished_yaml, 'P')
|
||||||
|
|
||||||
for section in finished_yaml:
|
for section in finished_yaml:
|
||||||
s_title = section['title']
|
s_title = section['title']
|
||||||
l_title = []
|
l_title = []
|
||||||
|
|
||||||
if len(s_title) > MAX_WIDTH_TITLE:
|
if len(s_title) > MAX_WIDTH_TITLE:
|
||||||
l_title = split_to_list(s_title, MAX_WIDTH_TITLE)
|
l_title = split_to_list(s_title, MAX_WIDTH_TITLE)
|
||||||
else:
|
else:
|
||||||
l_title = [s_title]
|
l_title = [s_title]
|
||||||
|
|
||||||
# Create section header
|
# Create section header
|
||||||
finished_result += build_header(l_title)
|
finished_result += build_header(l_title)
|
||||||
|
|
||||||
# Create table header
|
# Create table header
|
||||||
finished_result += ['______ ________________________________________________________ ',
|
finished_result += ['______ ________________________________________________________ ',
|
||||||
'======|========================================================|']
|
'======|========================================================|']
|
||||||
|
|
||||||
# Add games one by one
|
# Add games one by one
|
||||||
# Suffix : |
|
# Suffix : |
|
||||||
for game in section['games']:
|
for game in section['games']:
|
||||||
s_name = game['name']
|
s_name = game['name']
|
||||||
s_platform = game['platform']
|
s_platform = game['platform']
|
||||||
|
|
||||||
if len(s_platform) > MAX_WIDTH_PLATFORM:
|
if len(s_platform) > MAX_WIDTH_PLATFORM:
|
||||||
raise Exception(f"Platform shortcode for {s_name} is longer than 4 characters. Cannot parse...")
|
raise Exception(f"Platform shortcode for {s_name} is longer than 4 characters. Cannot parse...")
|
||||||
|
|
||||||
if len(s_name) > MAX_WIDTH_NAME:
|
if len(s_name) > MAX_WIDTH_NAME:
|
||||||
l_name = split_to_list(s_name, MAX_WIDTH_NAME)
|
l_name = split_to_list(s_name, MAX_WIDTH_NAME)
|
||||||
for i,i_name in enumerate(l_name):
|
for i,i_name in enumerate(l_name):
|
||||||
finished_result += [build_game(i_name, platform if i == 0 else '') + '|']
|
finished_result += [build_game(i_name, platform if i == 0 else '') + '|']
|
||||||
else:
|
else:
|
||||||
finished_result += [build_game(s_name, s_platform) + '|']
|
finished_result += [build_game(s_name, s_platform) + '|']
|
||||||
|
|
||||||
# Close table header
|
# Close table header
|
||||||
finished_result += ['______|________________________________________________________|',
|
finished_result += ['______|________________________________________________________|',
|
||||||
' ' * MAX_WIDTH]
|
' ' * MAX_WIDTH]
|
||||||
|
|
||||||
# adjust length of both sides
|
# adjust length of both sides
|
||||||
len_difference = len(todo_result) - len(finished_result)
|
len_difference = len(todo_result) - len(finished_result)
|
||||||
# todo > finished
|
# todo > finished
|
||||||
if len_difference > 0:
|
if len_difference > 0:
|
||||||
finished_result += [' ' * MAX_WIDTH] * len_difference
|
finished_result += [' ' * MAX_WIDTH] * len_difference
|
||||||
# todo < finished
|
# todo < finished
|
||||||
elif len_difference < 0:
|
elif len_difference < 0:
|
||||||
len_difference *= -1
|
len_difference *= -1
|
||||||
todo_result += [' ' * MAX_WIDTH] * len_difference
|
todo_result += [' ' * MAX_WIDTH] * len_difference
|
||||||
|
|
||||||
if len(todo_result) != len(finished_result):
|
if len(todo_result) != len(finished_result):
|
||||||
raise Exception("Results are not of equal size. Something went wrong...")
|
raise Exception("Results are not of equal size. Something went wrong...")
|
||||||
|
|
||||||
result = []
|
result = []
|
||||||
i = 0
|
i = 0
|
||||||
while len(todo_result) > i:
|
while len(todo_result) > i:
|
||||||
result += [todo_result[i] + DELIMITER + finished_result[i]]
|
result += [todo_result[i] + DELIMITER + finished_result[i]]
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
with open('list-of-game.txt', 'w') as file:
|
with open('list-of-game.txt', 'w') as file:
|
||||||
for i in result:
|
for i in result:
|
||||||
file.write(f"{i}\n")
|
file.write(f"{i}\n")
|
||||||
|
|
||||||
print('done')
|
print('done')
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue