diff --git a/README.md b/README.md index 109d4c7..37d28e6 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,8 @@ Currently the indexer has the following features - Add CSV sorting (Sort by book then alphabetical) - Add handling for repeat entries - Only show CSVs when asking which index you want to work on -- Add "Create new" option to csv selection option +- ~~Add "Create new" option to csv selection option~~ +![](createIndex.gif) - Create a .sansindex file in home directory that stores indexes - Add delete option for index files - Add "ask for book" prompt on startup diff --git a/createIndex.gif b/createIndex.gif new file mode 100644 index 0000000..21c611b Binary files /dev/null and b/createIndex.gif differ diff --git a/index.py b/index.py index ce93cf0..97de896 100755 --- a/index.py +++ b/index.py @@ -40,30 +40,33 @@ def init(): for i in csvCheck: if(i.endswith(".csv")): print(tickInfo,"CSV Exists in current directory, which would you like to use? ") + for i in os.listdir(): count+=1 dic[count]=i + print(sep) + # For each value, assign a key from 1-n. This will allow the user to select a number that corresponds to the csv file for key, value in dic.items(): - print(key, ' : ', value) + print(green, key, red,'-->', cyan , value, reset) + print(sep) + print(green, "0", red, "-->" + cyan + " New index") selection = input(tick + green + " Type the number of the file you would like\n" + reset) - - csvName = dic[int(selection)] - print(tick, "You chose: ", csvName) - - return csvName - - print("CSV Does not Exist") - csvName = input(tick + yellow + "What do you want to name your CSV file?\n" + reset) - if not csvName.endswith(".csv"): - csvName += ".csv" - print(csvName) - with open(csvName, 'a') as f: - write = csv.writer(f) - print("Adding headers") - write.writerow(headers) - - print(csvName) - return csvName + # If selecing existing csv, exit function + if selection != "0": + csvName = dic[int(selection)] + print(tick, "You chose: ", csvName) + return csvName + # If selection is to create a new CSV, carry on with creating it + else: + csvName = input(tick + yellow + "What do you want to name your CSV file?\n" + reset) + if not csvName.endswith(".csv"): + csvName += ".csv" + with open(csvName, 'a') as f: + write = csv.writer(f) + write.writerow(headers) + + print(csvName) + return csvName def writeCsv(): with open(csvName, 'a') as f: @@ -112,7 +115,6 @@ while True: # Append row to list called index (This is a list of a lists) index.append(strippedRow) writeCsv() - #readIndex(csvName)