|
|
|
@ -23,6 +23,7 @@ tickBad = Fore.YELLOW + "[" + Fore.RED + "X" + Fore.YELLOW+ "]" + reset
|
|
|
|
|
awaitingInput = Fore.BLUE + "-----" + Fore.GREEN + "> " + reset
|
|
|
|
|
tickInfo = Fore.BLUE + "[" + yellow + "!" + Fore.BLUE + "]" + reset
|
|
|
|
|
|
|
|
|
|
os.system("clear")
|
|
|
|
|
print(tick, "Welcome to Sans Terminal Indexer")
|
|
|
|
|
print(tick, "Enter" , green, "\"new book\"" , reset, "to change to the next book")
|
|
|
|
|
book = input("Which book are you currently working on?\n")
|
|
|
|
@ -37,54 +38,58 @@ def path():
|
|
|
|
|
|
|
|
|
|
# Handle control+c
|
|
|
|
|
def handler(signum, frame):
|
|
|
|
|
os.system("clear")
|
|
|
|
|
print(red, "Exiting")
|
|
|
|
|
exit(0)
|
|
|
|
|
signal.signal(signal.SIGINT, handler)
|
|
|
|
|
|
|
|
|
|
# Kick off program, check if any .csv files are in directory, if not, prompt user to create one
|
|
|
|
|
def init():
|
|
|
|
|
os.system("clear")
|
|
|
|
|
path()
|
|
|
|
|
count = 0
|
|
|
|
|
csvCheck = os.listdir()
|
|
|
|
|
print(csvCheck)
|
|
|
|
|
|
|
|
|
|
# If a .csv file exists in the current directory (~.Indexes) then prompt user for which one they would like to use
|
|
|
|
|
if any(".csv" in c for c in csvCheck):
|
|
|
|
|
print(tickInfo,"CSV Exists in current directory, which would you like to use? ")
|
|
|
|
|
# For each file that ends in .csv, add to dictionary, then 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 x in os.listdir():
|
|
|
|
|
if x.endswith((".csv")):
|
|
|
|
|
count+=1
|
|
|
|
|
dictionary[count]=x
|
|
|
|
|
print(sep)
|
|
|
|
|
# For each key and value, in the dictionary, print key, value for user to select from
|
|
|
|
|
for key, value in dictionary.items():
|
|
|
|
|
print(green, key, red,'-->', cyan , value, reset)
|
|
|
|
|
print(sep)
|
|
|
|
|
print(green, "0", red, "-->" + cyan + " New index")
|
|
|
|
|
|
|
|
|
|
# Ask the user which file they would like
|
|
|
|
|
selection = input(tick + green + " Type the number of the file you would like\n" + reset)
|
|
|
|
|
|
|
|
|
|
# If selecing existing csv, set csvName to choice and exit function
|
|
|
|
|
if selection != "0":
|
|
|
|
|
csvName = dictionary[int(selection)]
|
|
|
|
|
print(tick, "You chose: ", csvName)
|
|
|
|
|
return csvName
|
|
|
|
|
|
|
|
|
|
# If selection is not to select a current CSV, create a new one
|
|
|
|
|
else:
|
|
|
|
|
csvName = input(tick + green + "Creating a new index, what do you want to name your CSV file?\n" + reset)
|
|
|
|
|
for i in csvCheck:
|
|
|
|
|
print("printing elements", i)
|
|
|
|
|
if (i.endswith(".csv")):
|
|
|
|
|
print(tickInfo,"CSV Exists in current directory, which would you like to use? ")
|
|
|
|
|
# For each file that ends in .csv, add to dictionary, then 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 x in os.listdir():
|
|
|
|
|
if x.endswith((".csv")):
|
|
|
|
|
count+=1
|
|
|
|
|
dictionary[count]=x
|
|
|
|
|
print(sep)
|
|
|
|
|
# For each key and value, in the dictionary, print key, value for user to select from
|
|
|
|
|
for key, value in dictionary.items():
|
|
|
|
|
print(green, key, red,'-->', cyan , value, reset)
|
|
|
|
|
print(sep)
|
|
|
|
|
print(green, "0", red, "-->" + cyan + " New index")
|
|
|
|
|
|
|
|
|
|
if not csvName.endswith(".csv"):
|
|
|
|
|
csvName += ".csv"
|
|
|
|
|
# Ask the user which file they would like
|
|
|
|
|
selection = input(tick + green + " Type the number of the file you would like\n" + reset)
|
|
|
|
|
|
|
|
|
|
# If selecing existing csv, set csvName to choice and exit function
|
|
|
|
|
if selection != "0":
|
|
|
|
|
csvName = dictionary[int(selection)]
|
|
|
|
|
print(tick, "You chose: ", csvName)
|
|
|
|
|
return csvName
|
|
|
|
|
|
|
|
|
|
csvName = input(tick + green + " Creating a new index, 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)
|
|
|
|
|
with open(csvName, 'a') as f:
|
|
|
|
|
write = csv.writer(f)
|
|
|
|
|
write.writerow(headers)
|
|
|
|
|
|
|
|
|
|
print(csvName)
|
|
|
|
|
return csvName
|
|
|
|
|
print(tick, "Creating file named: ", csvName)
|
|
|
|
|
os.system("clear")
|
|
|
|
|
return csvName
|
|
|
|
|
|
|
|
|
|
def writeCsv():
|
|
|
|
|
with open(csvName, 'a') as f:
|
|
|
|
@ -92,7 +97,8 @@ def writeCsv():
|
|
|
|
|
write.writerows(index)
|
|
|
|
|
|
|
|
|
|
def readIndex(csvName):
|
|
|
|
|
print(tick, "Displaying abbreviated entries for",cyan, csvName,reset)
|
|
|
|
|
os.system("clear")
|
|
|
|
|
print(tick, "Displaying entries for",cyan, csvName,reset)
|
|
|
|
|
df = pd.read_csv(csvName)
|
|
|
|
|
#bottom = df.tail()
|
|
|
|
|
print(df)
|
|
|
|
|