76 lines
1.8 KiB
Python
76 lines
1.8 KiB
Python
from jinja2 import Environment, FileSystemLoader
|
||
import os
|
||
|
||
def column_code(num):
|
||
result = ''
|
||
alfa_count = 1 + ord('Z') - ord('A')
|
||
shift = ord('A') - 1
|
||
while num > 0:
|
||
if num <= alfa_count:
|
||
result = chr(shift + num) + result
|
||
num = 0
|
||
else:
|
||
cur_chr = ((num -1) % alfa_count) + 1
|
||
num = int((num -1) / alfa_count)
|
||
result = chr(shift + cur_chr) + result
|
||
return result
|
||
|
||
|
||
def column_num(code):
|
||
result = 0
|
||
alfa_count = 1 + ord('Z') - ord('A')
|
||
shift = ord('A') - 1
|
||
mult = 1
|
||
length = len(code)
|
||
while length > 0:
|
||
cur_chr = code[-1]
|
||
result = result + mult * (ord(cur_chr) - shift)
|
||
length -= 1
|
||
if 0 == length:
|
||
code = ''
|
||
else:
|
||
code = code[:-1]
|
||
mult *= alfa_count
|
||
return result
|
||
|
||
|
||
def generate_columns():
|
||
column_start = column_num('H')
|
||
column_end = column_num('ZZ')
|
||
column_current = column_start
|
||
while(column_current <= column_end):
|
||
yield column_code(column_current)
|
||
column_current += 1
|
||
|
||
|
||
def render_template(name, template):
|
||
vals = {
|
||
'сol_start': 'H',
|
||
'row_num': 4,
|
||
'fixed_row': 3,
|
||
'columns': [c for c in generate_columns()]
|
||
}
|
||
print(template.render(vals))
|
||
|
||
|
||
def init_templates():
|
||
names = ['wins_formula', 'wins_red_formula', 'wins_black_formula']
|
||
templates = {}
|
||
env = Environment(
|
||
loader=FileSystemLoader(os.path.join(os.path.dirname(os.path.dirname(__file__)),'templates'))
|
||
)
|
||
for name in names:
|
||
templates[name] = env.get_template(f'{name}.jinja2')
|
||
return templates
|
||
|
||
|
||
def main():
|
||
templates = init_templates()
|
||
for template in templates.items():
|
||
print(template[0], template[1])
|
||
render_template(template[0], template[1])
|
||
|
||
|
||
if __name__ == "__main__":
|
||
main()
|