Skip to content

Commit

Permalink
csv to cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Asiern committed Oct 13, 2021
1 parent 8154059 commit 7803dc7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -337,4 +337,7 @@ ASALocalRun/
.localhistory/

# BeatPulse healthcheck temp database
healthchecksdb
healthchecksdb

# CSV
*.csv
33 changes: 33 additions & 0 deletions Scripts/csv_to_cpp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import os
import sys
import getopt
import csv

try:
opts, args = getopt.getopt(sys.argv[1:], "hf:", ["file"])
except getopt.GetoptError:
print('csv_to_cpp.py -f <file.csv>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print('csv_to_cpp.py -f <file.csv>')
sys.exit()
elif opt in ("-f", "--file"):
path = arg
# elif opt in ("-p", "--prefix"):
# prefix = arg
# elif opt in ("-s", "-sufix"):
# sufix = arg


f = open("out.cpp", "w")

category = ""
with open(path, newline="") as file:
reader = csv.reader(file, delimiter=",", quotechar="|")
next(reader)
for row in reader:
if row[0] != "":
category = row[0]
f.write("\n// "+category+"\n")
f.write("_"+category+'->Add("' + row[1] + '");'+ "\n")

0 comments on commit 7803dc7

Please sign in to comment.