forked from BrennanKolotinsky/markdownTableAutomator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmarkdownCreator.py
32 lines (26 loc) · 1.08 KB
/
markdownCreator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import csv
cols = 0
f = open("README.md", "a") # a indicates you can write to the file!
f.truncate(0) # delete existing content in file
f.write("# Table Markdown Automator")
f.write("\nTo create a markdown chart: \n* Pull this code \n* Place your CSV file in the root directory of this code \n* Run ```python markdownCreator.py``` \n* Type the name of your CSV file when prompted")
f.write("\n\nThe output will be markdown in the README.md file")
fName = input("Please enter the name of your csv file!");
if (fName == ""):
print("Using default file input - Bill of Material.csv");
fName = "Bill of Material.csv"
with open(fName) as csv_file:
csv_reader = csv.reader(csv_file, delimiter=',')
line_count = 0
cols = 0
for row in csv_reader:
if line_count == 0:
f.write("\n| " + " | ".join(row) + " |")
cols = len(row)
f.write("\n| " + " - |" * cols)
line_count += 1
else:
f.write("\n| " + " | ".join(row) + " |")
line_count += 1
print(f'Processed {line_count} lines.')
f.close()