Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- import docx
- import codecs
- def find_table_title(line):
- result = re.search(r'(?<=<tr><td width="100%" class="tabletitle"><b>)\w+', line)
- if result:
- return result.group(0)
- def find_table_sub_title(line):
- result = re.search(r'(?<=<tr><td width="100%" class="tablesubtitle"><b>)\w+', line)
- if result:
- return result.group(0)
- def find_type_return(line):
- result = re.search(r'(?<=<tr><td colspan="2"><span class="function"><span class="arg">)\w+', line)
- if result:
- return result.group(0)
- def find_name_function(line):
- result = re.search(r'\w+', line)
- if result:
- return result.group(0)
- def find_description_function(line):
- result = re.search(r'(?<=<p>)[\w+\s]+', line)
- if result:
- return result.group(0)
- def find_args(line):
- type_arg = re.findall(r'(?<=<span class="arg">)\w+', line)
- name_arg = re.findall(r'(?<=</span> )\w+', line)
- result = dict()
- for key, value in zip(type_arg, name_arg):
- result[key] = value
- if type_arg:
- return result
- doc = docx.Document()
- style = doc.styles['Normal']
- style.font.size = docx.shared.Pt(14)
- with codecs.open('function_list.htm', "r", "utf-16") as file:
- with open('function_list_to_github.txt', 'w') as file_write:
- for line in file:
- if find_table_title(line):
- doc.add_paragraph(find_table_title(line), style='Title')
- file_write.write(f'# {find_table_title(line)}\n')
- elif find_table_sub_title(line):
- doc.add_paragraph(find_table_sub_title(line), style='Title')
- file_write.write(f'# {find_table_sub_title(line)}\n')
- elif find_type_return(line):
- next_line = file.readline()
- paragraph = doc.add_paragraph()
- paragraph.add_run(f'{find_type_return(line)} ').italic = True
- paragraph.add_run(find_name_function(next_line)).bold = True
- file_write.write(f'## {find_type_return(line)} {find_name_function(next_line)}\n\n')
- dict_args = find_args(next_line)
- file_write.write('Type | Name\n')
- file_write.write('------ | ------\n')
- if dict_args:
- for key, value in dict_args.items():
- file_write.write(f'{key} | {value}\n')
- doc.add_paragraph(f'Тип аргумента: {key}, имя аргумента: {value}', style='List Bullet')
- file_write.write('\n')
- elif find_description_function(line):
- doc.add_paragraph(find_description_function(line))
- file_write.write(f'{find_description_function(line)}\n')
- doc.save('function_list.docx')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement