def convert(csv_file_path, html_file_path,table_name): print("this python script read table in ",csv_file_path, " and then write it into html file ",html_file_path) print("converting...") #writer = HtmlTableWriter() writer = MarkdownTableWriter() #writer.is_write_header=False writer.from_csv(csv_file_path) writer.table_name = table_name #get the column for link link_col=0 for head in writer.headers: #print(head) if ( head == 'website' ): break else: link_col +=1 #debug link_col_flag = True if ( link_col >= len(writer.headers) ): link_col_flag = False #raise ValueError('no column for link') print('get link_col = ',link_col) #get the column for wuzi wuzi_col=0 for head in writer.headers: #print(head) if ( head == 'repo' ): break else: wuzi_col +=1 #debug wuzi_col_flag = True if ( wuzi_col >= len(writer.headers) ): wuzi_col_flag = False #raise ValueError('no column for wuzi') print('get wuzi_col = ',wuzi_col) #limit width of some column to be col_fixed_width=wuzi_col col_width=24 #modify the link in the fourth row to be an html link for row in writer.value_matrix: if wuzi_col_flag and ( row[wuzi_col] != '' ): row[wuzi_col]='[repo]('+row[wuzi_col]+')' if link_col_flag and ( row[link_col] != '' ): row[link_col]='[website]('+row[link_col]+')' writer.dump(html_file_path) print("done with ",table_name)
def main(): # prepare data --- csv_file_path = "data.csv" markdown_file_path = ("data.md") print("this python script read table in ", csv_file_path, " and then write it into markdown file ", markdown_file_path) print("converting...") writer = MarkdownTableWriter() writer.from_csv(csv_file_path) writer.margin = 1 writer.dump(markdown_file_path) print("done")