Added new features

Now only lists files with .csv extenions and asks for book on startup
main
Graham Helton 2 years ago
parent 7ec6cc5b46
commit 60888fe323

@ -19,10 +19,10 @@ Currently the indexer has the following features
- Add edit feature (edit previous index entries) - Add edit feature (edit previous index entries)
- Add CSV sorting (Sort by book then alphabetical) - Add CSV sorting (Sort by book then alphabetical)
- Add handling for repeat entries - Add handling for repeat entries
- Only show CSVs when asking which index you want to work on - ~~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~~
![](createCsv.gif) ![](createCsv.gif)
- Create a .sansindex file in home directory that stores indexes - Create a .sansindex file in home directory that stores indexes
- Add delete option for index files - Add delete option for index files
- Add "ask for book" prompt on startup - ~~Add "ask for book" prompt on startup~~
- Allow for input with no definition (term, pagenumber) - ~~Allow for input with no definition (term, pagenumber)~~

@ -8,7 +8,6 @@ from colorama import Fore, Style
headers = ['Title', 'Description','Page','book'] headers = ['Title', 'Description','Page','book']
index = [] index = []
row = [] row = []
book = "1"
dic = {} dic = {}
# Define formatting # Define formatting
reset = Style.RESET_ALL reset = Style.RESET_ALL
@ -24,8 +23,8 @@ awaitingInput = Fore.BLUE + "-----" + Fore.GREEN + "> " + reset
tickInfo = Fore.BLUE + "[" + yellow + "!" + Fore.BLUE + "]" + reset tickInfo = Fore.BLUE + "[" + yellow + "!" + Fore.BLUE + "]" + reset
print(tick, "Welcome to Sans Terminal Indexer") print(tick, "Welcome to Sans Terminal Indexer")
print(tick, "Setting default book number to 1") print(tick, "Enter" , green, "\"new book\"" , reset, "to change to the next book")
print(tick, "Enter \"new book\" to change to the next book") book = input("Which book are you currently working on?\n")
# Handle control+c # Handle control+c
def handler(signum, frame): def handler(signum, frame):
@ -36,16 +35,19 @@ signal.signal(signal.SIGINT, handler)
# Kick off program, check if any .csv files are in directory, if not, prompt user to create one # Kick off program, check if any .csv files are in directory, if not, prompt user to create one
def init(): def init():
count = 0 count = 0
csvCheck = os.listdir('.') csvCheck = os.listdir()
for i in csvCheck: for i in csvCheck:
if(i.endswith(".csv")): if any(".csv" in c for c in csvCheck):
print(tickInfo,"CSV Exists in current directory, which would you like to use? ") print(tickInfo,"CSV Exists in current directory, which would you like to use? ")
for i in os.listdir(): for x in os.listdir():
count+=1 if x.endswith((".csv")):
dic[count]=i count+=1
dic[count]=x
print(sep) 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 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(): for key, value in dic.items():
print(green, key, red,'-->', cyan , value, reset) print(green, key, red,'-->', cyan , value, reset)
print(sep) print(sep)
@ -57,23 +59,23 @@ def init():
print(tick, "You chose: ", csvName) print(tick, "You chose: ", csvName)
return csvName return csvName
# If selection is to create a new CSV, carry on with creating it # If selection is to create a new CSV, carry on with creating it
else: else:
csvName = input(tick + yellow + "What do you want to name your CSV file?\n" + reset) csvName = input(tick + green + "Creating a new index, what do you want to name your CSV file?\n" + reset)
if not csvName.endswith(".csv"): if not csvName.endswith(".csv"):
csvName += ".csv" csvName += ".csv"
with open(csvName, 'a') as f: with open(csvName, 'a') as f:
write = csv.writer(f) write = csv.writer(f)
write.writerow(headers) write.writerow(headers)
print(csvName) print(csvName)
return csvName return csvName
def writeCsv(): def writeCsv():
with open(csvName, 'a') as f: with open(csvName, 'a') as f:
write = csv.writer(f) write = csv.writer(f)
write.writerows(index) write.writerows(index)
def readIndex(csvName): def readIndex(csvName):
print(tick, "Displaying abbreviated entries") print(tick, "Displaying abbreviated entries for",cyan, csvName,reset)
df = pd.read_csv(csvName) df = pd.read_csv(csvName)
#bottom = df.tail() #bottom = df.tail()
print(df) print(df)

Loading…
Cancel
Save