From caa1ad39037bc5c7d5d2d6d4a77aba13cfbe1826 Mon Sep 17 00:00:00 2001 From: Graham Helton Date: Mon, 28 Feb 2022 04:09:12 -0500 Subject: [PATCH] Added pretty printing by typing index --- README.md | 3 ++- index.py | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index da623fb..d325832 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ Currently the indexer has the following features # Todo -- Add index viewer within program (Pretty print index.csv) +- ~~Add index viewer within program (Pretty print index.csv)~~ - Add edit feature (edit previous index entries) - Add CSV sorting (Sort by book then alphabetical) - Add handling for repeat entries @@ -23,3 +23,4 @@ Currently the indexer has the following features - Create a .sansindex file in home directory that stores indexes - Add delete option for index files - Add "ask for book" prompt on startup +- Allow for input with no definition (term, pagenumber) diff --git a/index.py b/index.py index fa161eb..ce93cf0 100755 --- a/index.py +++ b/index.py @@ -2,6 +2,7 @@ import csv import os import signal +import pandas as pd from colorama import Fore, Style headers = ['Title', 'Description','Page','book'] @@ -68,6 +69,11 @@ def writeCsv(): with open(csvName, 'a') as f: write = csv.writer(f) write.writerows(index) +def readIndex(csvName): + print(tick, "Displaying abbreviated entries") + df = pd.read_csv(csvName) + #bottom = df.tail() + print(df) csvName = str(init()) # Get user input @@ -84,19 +90,29 @@ while True: elif newEntry == "new book": book = str(input(yellow + "Enter the book number\n")) + elif newEntry == "index": + readIndex(csvName) + elif newEntry.count(',') != 2: print(newEntry.count(',')) print(tickBad + " Try again, make sure you have 2 commas") else: # Clear screen os.system("clear") + # Split user input on commas and put into row variable row = newEntry.split(",") + + # Strip whitespace + strippedRow = [x.strip(' ') for x in row] + # append the book number to the end of the list - row.append(book) + strippedRow.append(book) + # Append row to list called index (This is a list of a lists) - index.append(row) + index.append(strippedRow) writeCsv() + #readIndex(csvName)