vocabCLI.modules package#

Submodules#

vocabCLI.modules.About module#

vocabCLI.modules.About.print_about_app() None[source]#

Prints the about app page

  1. Create a layout object

  2. Create a header content object with the help of the Panel class

  3. Create a footer content object with the help of the Panel class

  4. Create a main content object with the help of the Panel class

  5. Divide the “screen” into three parts

  6. Update the header, main and footer with their respective content objects

  7. Print the layout which contains details about the app

vocabCLI.modules.Banner module#

vocabCLI.modules.Banner.get_terminal_width() int[source]#

Gets the width of the terminal.

Returns:

int: width of the terminal.

vocabCLI.modules.Banner.print_banner(console) None[source]#

Prints the banner of the application.

Args:

console (Console): Rich console object.

vocabCLI.modules.Carousel module#

vocabCLI.modules.Carousel.show_slider() None[source]#
  1. Sets up the GUI window

  2. Dumps the images to the folder

  3. Deletes the images if already existing

  4. Sets up the images

  5. Creates a global counter variable

vocabCLI.modules.Database module#

vocabCLI.modules.Database.createConnection()[source]#

Creates a database connection to a SQLite database VocabularyBuilder.db

Returns:

Connection object or None.

vocabCLI.modules.Database.createTables(conn: Connection) None[source]#
  1. Creates the tables in the database if they do not exist

  2. Tables created are words, cache_words, collections, quiz_history, quotes, rss

  3. The tables are created using the SQL statements in the docstring with respective column names and data types

  4. The tables are created using the execute method of the connection object

  5. The connection object is passed as an argument to the function

Args:

conn (sqlite3.Connection): Connection object

vocabCLI.modules.Database.initializeDB() None[source]#

Initializes the database

vocabCLI.modules.Database.refresh_cache() None[source]#

Refreshes the cache of the words in the database.

  1. Connect to the database

  2. Check if the cache is empty, if yes, then do nothing.

  3. If the cache is not empty, then we need to refresh it.

  4. Get all the words from the cache.

  5. For each word, get the response from the API and update the cache.

  6. If there’s an error, then show a error message and exit.

  7. If there’s no error, then update the cache.

  8. If the cache is updated, then show a success message.

vocabCLI.modules.Dictionary module#

vocabCLI.modules.Dictionary.connect_to_api(query: str = 'hello') str[source]#

Connects to the API and returns the response in JSON format.

  1. Connect to the internet to check if the word is a valid word.

  2. If the word is a valid word, then check if the word is already in the cache_word table. If the word is in the cache_word table, then return the response from the cache_word table.

  3. If the word is not in the cache_word table, then connect to the API, get the response and then insert the word and its response into the cache_word table.

  4. If the word is not a valid word, then print an error message.

Args:

query (str, optional): Word to lookup to test the API. Defaults to “hello”.

Returns:

dict: Response in JSON format.

Raises:

ConnectionError: If the user is not connected to the internet. HTTPError: If the word is not a valid word. Timeout: If the request times out.

vocabCLI.modules.Dictionary.definition(query: str, short: Optional[bool] = False) None[source]#

Prints the definition of the word.

  1. The function definition first calls the function connect_to_api which takes query (str) as argument and returns the response (dict) if successful or None if unsuccessful.

  2. The function definition then calls the function phonetic which takes query (str) as argument and returns the phonetic (str) of the word.

  3. The function definition then calls the function insert_word_to_db which takes query (str) as argument and inserts the word into the database.

  4. If the short is set to True, the function definition then iterates over the meanings (dict) and prints the first definition (str) of the word.

  5. If the short is set to False, the function definition then calls the function display_theme which takes query (str) as argument and displays the theme (str) associated with the word.

  6. The function definition then calls the function show_commonly_confused which takes query (str) as argument and displays the commonly confused words (str) of the word.

  7. The function definition then iterates over the meanings (dict) and prints the definition (str) and example (str) of the word.

Args:

query (str): Word which is meant to be defined. short (Optional[bool], optional): If True, it will print just the short definition. Defaults to False.

vocabCLI.modules.Dictionary.display_theme(query: str) None[source]#

Display the theme of the word if it exists in the collections table

  1. Create a connection to the database

  2. Create a cursor to execute SQL queries on the database

  3. Execute an SQL query that returns the collection name for a given word

  4. If the query returns a result, print it

Args:

query (str): Word to check if it has a theme

vocabCLI.modules.Dictionary.get_word_of_the_day() None[source]#

Get a word of the day from a public API and print its definition.

  1. Get the API key from the environment variables

  2. Send a GET request to the Wordnik API to get the word of the day

  3. Get the word from the response

  4. Print the word & definition of the word of the day

vocabCLI.modules.Dictionary.insert_to_db_util(conn, query: str) None[source]#

Inserts the word into the database.

  1. If the word exists in the database, with a tag, then insert it with that tag.

  2. If the word exists in the database, without a tag, then insert it without a tag.

  3. If the word exists in the database, with favorite 1, then insert it with favorite 1.

  4. If the word exists in the database, with learning 1, then insert it with learning 1.

  5. If the word exists in the database, with mastered 1, then insert it with mastered 1.

Args:

conn (sqlite3.Connection): Connection to the database. query (str): Word to be inserted into the database.

vocabCLI.modules.Dictionary.insert_word_to_db(query: str) None[source]#

Add the word in the vocabulary builder list.

The code above does the following, explained in English: 1. Check if the word exists in the cache_word table 2. If the word exists, then insert the word to the database 3. If the word does not exist, then query the API to check if the word exists 4. If the word exists, then insert the word to the database and also insert the word and its response to the cache_word table

Args:

query (str): Word which is to be tagged.

vocabCLI.modules.Dictionary.one_line_definition(query: str) str[source]#

Prints the one line definition of the word.

Args:

query (str): Word which is meant to be defined.

vocabCLI.modules.Dictionary.phonetic(query: str) str[source]#

Prints the phonetic of the word.

  1. It takes the query as an argument.

  2. It connects to the API and retrieves the response.

  3. If the word is not found in the dictionary, it prints the message.

  4. If the word is found, it loops through the phonetics.

  5. If the phonetic is available, it returns it.

  6. If the phonetic is not available, it prints ‘Phonetic Unavailable’.

Args:

query (str): Word for which phonetic is to be printed.

Returns:

string: Phonetic of the word.

vocabCLI.modules.Dictionary.say_aloud(query: str) None[source]#

Pronounces the word. Downloads the audio file, plays it and deletes it.

  1. The function say_aloud first calls the function connect_to_api which takes query (str) as argument and returns the response (dict) if successful or None if unsuccessful.

  2. The function say_aloud then checks if the audio is available or not.

  3. If the audio is available, the function say_aloud then downloads the audio file and plays it.

  4. If the audio is not available, the function say_aloud then raises the AudioUnavailableException.

  5. The function say_aloud then deletes the audio file.

  6. The function say_aloud then prints the phonetic (str) of the word.

Args:

query (str): Word to be pronounced.

Raises:

AudioUnavailableException: Raised when the audio is not available.

vocabCLI.modules.Dictionary.show_commonly_confused(word: str) None[source]#

Check if the word is commonly confused with other words, if yes, show them

  1. Open the commonly_confused.csv file

  2. Read the file

  3. If the word is in the row, then print the words in the row as commonly confused words

  4. If the word is not in the row, then do nothing

Args:

word (str): Word to check if it is commonly confused with other words

vocabCLI.modules.Exceptions module#

exception vocabCLI.modules.Exceptions.AudioUnavailableException[source]#

Bases: Exception

raised when the audio is not available for the word.

exception vocabCLI.modules.Exceptions.NoDataFoundException[source]#

Bases: Exception

raised when the user attempts to export data but there is no data to export.

exception vocabCLI.modules.Exceptions.NoQuotesException[source]#

Bases: Exception

raised when the user attempts to perform some operation on a quote which is not present in the list.

exception vocabCLI.modules.Exceptions.NoRSSFeedsException[source]#

Bases: Exception

raised when the user attempts to perform some operation on a RSS feed which is not present in the list.

exception vocabCLI.modules.Exceptions.NoSuchCollectionException(collection)[source]#

Bases: Exception

raised when the user attempts to perform some operation on a collection which is not present in the list.

collection = None#
exception vocabCLI.modules.Exceptions.NoSuchTagException(tag)[source]#

Bases: Exception

raised when the user attempts to perform some operation on a tag which is not present in the list.

tag = None#
exception vocabCLI.modules.Exceptions.NoWordsInDBException[source]#

Bases: Exception

raised when the user attempts to perform some operation on a word which is not present in the database.

exception vocabCLI.modules.Exceptions.NoWordsInFavoriteListException[source]#

Bases: Exception

raised when the user attempts to start a learning session but there are no words in the list.

exception vocabCLI.modules.Exceptions.NoWordsInLearningListException[source]#

Bases: Exception

raised when the user attempts to start a learning session but there are no words in the list.

exception vocabCLI.modules.Exceptions.NoWordsInMasteredListException[source]#

Bases: Exception

raised when the user attempts to start a learning session but there are no words in the list.

exception vocabCLI.modules.Exceptions.NotEnoughWordsForQuizException[source]#

Bases: Exception

raised when the user attempts to start a quiz but there are not enough words in the list.

exception vocabCLI.modules.Exceptions.WordNeverSearchedException(word)[source]#

Bases: Exception

raised when a word is never searched but user attempts to perform some operation on it.

word = None#

vocabCLI.modules.Flashcard module#

vocabCLI.modules.Flashcard.export_util(c, type: str)[source]#

Exports the words from the database to a flashcard image

Args:

c (sqlite3.Cursor): The cursor object type (str): The type of words to be exported

vocabCLI.modules.Flashcard.flashcard_definition(query: str) str[source]#

Returns the definition of the word from the cache.

  1. Execute a query that selects the api_response column from the cache_words table where the word column is equal to the query

  2. Load the api_response column as a JSON object

  3. Create an empty dictionary

  4. Loop through each meaning in the meanings array

  5. For each meaning, loop through the first 3 definitions

  6. For each definition, add it to the dictionary with the key being the definition and the value being the example if it exists

  7. Return the first 3 definitions and examples

Args:

query (str): The word to be searched

Returns:

str: The definition of the word

vocabCLI.modules.Flashcard.generate_all_flashcards()[source]#

Generate flashcards for all words in the database

vocabCLI.modules.Flashcard.generate_favorite_flashcards()[source]#

Generate flashcards for all favorite words in the database

vocabCLI.modules.Flashcard.generate_learning_flashcards()[source]#

Generate flashcards for all learning words in the database

vocabCLI.modules.Flashcard.generate_mastered_flashcards()[source]#

Generate flashcards for all mastered words in the database

vocabCLI.modules.Flashcard.generate_tag_flashcards(query: str)[source]#

Generate flashcards for all words with a specific tag in the database

Args:

query (str): the tag to search for

vocabCLI.modules.Flashcard.interpolate(black, random_color, interval)[source]#

Interpolate between two colors.

  1. It calculates the difference between the two colors

  2. It divides the difference by the number of steps

  3. It adds the difference to the black color each time it moves one step

  4. It returns the new color, rounded to the nearest integer

  5. It does this for each step

Args:

black (tuple): The first color random_color (tuple): The second color interval (int): The number of steps to take between the two colors

vocabCLI.modules.Graph module#

vocabCLI.modules.Graph.viz_learning_vs_mastered(popup: bool = False) None[source]#

Visualizes the distribution of words by learning and mastered.

  1. Count number of words in learning and mastered.

  2. Set the style of the graph.

  3. Plot a pie chart.

  4. Export the graph as png.

  5. Show the graph in a popup window if popup=True.

Args:

popup (bool, optional): Whether to show the graph in a popup window. Defaults to False.

vocabCLI.modules.Graph.viz_top_tags_bar(N: int = 10, popup: bool = False) None[source]#

Visualizes the top N tags with the most words.

  1. Get the top N tags and their word count from the database and store them in a list

  2. If no words are found, print an error message and return

  3. If there are less words than the number we want to display, print a warning message

  4. Create a dataframe from the list

  5. Set the style of the graph

  6. Plot the graph

  7. Export the graph to a png file

  8. If popup is True, show the graph in a popup window

Args:

N (int, optional): Number of top tags to visualize . Defaults to 10. popup (bool, optional): Whether to show the graph in a popup window. Defaults to False.

vocabCLI.modules.Graph.viz_top_tags_pie(N: int = 10, popup: bool = False) None[source]#

Visualizes the top N tags with the most words.

  1. Execute a SQL query to get the count of each tag. The query returns a list of tuples, where the first element is the tag and the second is the count.

  2. If no words are found, print an error message and return

  3. If there are less words than the number we want to display, print a warning message

  4. Create a dataframe from the list of tags and the list of counts.

  5. Set the theme of the plot.

  6. Create a pie chart using the dataframe.

  7. Save the plot in a file.

  8. Check if the directory exists, if not create it.

  9. Show the plot on screen if the popup argument is true.

Args:

N (int, optional): Number of top tags to visualize . Defaults to 10.

vocabCLI.modules.Graph.viz_top_words_bar(N: int = 10, popup: bool = False) None[source]#

Visualize the top N words looked up by the user

  1. Get the top N words and their word count from the database and store them in a list

  2. If no words are found, print an error message and return

  3. If there are less words than the number we want to display, print a warning message

  4. Create a dataframe from the list

  5. Set the style of the graph

  6. Plot the graph

  7. Export the graph to a png file

  8. If popup is True, show the graph in a popup window

Args:

N (int, optional): Number of words to visualize. Defaults to 10. popup (bool, optional): Whether to show the graph in a popup window. Defaults to False.

vocabCLI.modules.Graph.viz_top_words_pie(N: int = 10, popup: bool = False) None[source]#

Visualizes the top N words with the most lookups.

  1. Create a cursor and execute a query to fetch the word and the count of the word from the database

  2. If no words are found, print an error message and return

  3. If there are less words than the number we want to display, print a warning message

  4. Create a dataframe using the top words and their counts

  5. Create a pie chart using matplotlib and seaborn and save it to a file

  6. If the popup parameter is True, display the pie chart using matplotlib

Args:

N (int, optional): Number of top words to visualize . Defaults to 10. popup (bool, optional): Whether to show the graph in a popup window. Defaults to False.

vocabCLI.modules.Graph.viz_word_distribution_category(popup: bool = False) None[source]#

Visualizes the distribution of words by category.

  1. Selects the collection column and the word count from the words and collections table.

  2. Creates a dataframe from the data obtained.

  3. Sets the style of the graph.

  4. Creates a bar graph based on the dataframe.

  5. Saves the graph to the exports folder.

  6. Displays graph if popup is True.

Args:

popup (bool, optional): Whether to show the graph in a popup window. Defaults to False.

vocabCLI.modules.Graph.viz_word_distribution_month(popup: bool = False) None[source]#

Visualizes the distribution of words by dates of month.

  1. Get the data from the function word_distribution_month_util() which is a list of:
    1. Dates

    2. Word count

  2. Create a dataframe from the list

  3. Set the style of the graph

  4. Plot the graph

  5. Set the graph title, x and y axis labels, and x axis tick labels

  6. Save the graph to the folder ‘exports’

  7. If popup is True, show the graph in a popup window

Args:

popup (bool, optional): Whether to show the graph in a popup window. Defaults to False.

vocabCLI.modules.Graph.viz_word_distribution_week(popup: bool = False) None[source]#

Visualizes the distribution of words by day of the week.

  1. Create a dataframe from a list of tuples (day, count).

  2. Set the style of the graph.

  3. Plot the graph with the dataframe.

  4. Set the title, x and y labels, x and y ticks.

5. Save the graph. 5. Show the graph in a popup window if popup is True.

Args:

popup (bool, optional): Whether to show the graph in a popup window. Defaults to False.

vocabCLI.modules.Graph.viz_word_distribution_year(popup: bool = False)[source]#
vocabCLI.modules.Graph.word_distribution_month_util() tuple[list, list][source]#

Returns the distribution of word by dates of month.

  1. Determine current year, current month and next month.

  2. Determine total number of days in current month.

  3. Get unformatted datestrings for each day in current month.

  4. Get word count for each day in current month.

Returns:

list: List of dates of month. list: List of word counts.

vocabCLI.modules.Graph.word_distribution_year_util()[source]#
vocabCLI.modules.Graph.words_distribution_week_util() tuple[list, list][source]#

Returns the distribution of words by day of the week.

  1. Create a dictionary with numbers as keys and weekdays as values.

  2. Create two lists, one for weekdays and one for word count.

  3. Query the database for word count for each day in the current week.

  4. Loop through the results and assign the weekday to the list.

  5. Assign the word count to the list.

  6. Return the two lists.

Returns:

list: list of days of the week. list: list of days of the word counts.

vocabCLI.modules.ImportExport module#

class vocabCLI.modules.ImportExport.PDF(orientation='P', unit='mm', format='A4')[source]#

Bases: FPDF

footer()[source]#

Page footer.

header()[source]#

Header to be implemented in your own inherited class

vocabCLI.modules.ImportExport.export_to_csv() None[source]#

Export words to csv file.

  1. Create a connection to the database.

  2. Create a cursor object.

  3. Execute a SELECT query to fetch all the words from the database.

  4. Write the words to a csv file.

  5. Execute a SELECT query to fetch all the quotes from the database.

  6. Write the quotes to a csv file.

  7. Execute a SELECT query to fetch all the rss feeds from the database.

  8. Write the rss feeds to a csv file.

  9. Execute a SELECT query to fetch all the quiz history from the database.

  10. Write the quiz history to a csv file.

  11. Close the connection.

Raises:

NoDataFoundException: If no words are found in the database.

vocabCLI.modules.ImportExport.export_to_pdf() None[source]#

Export words to pdf file.

  1. Create a pdf file

  2. Sets all the attributes (colour, font, size, etc.)

  3. Execute a query to select all words from the database

  4. If there are no rows, raise NoDataFoundException

  5. Create a cell for respective column and fill it with the data

Raises:

NoDataFoundException: If no words are found in the database.

vocabCLI.modules.ImportExport.import_from_csv() None[source]#

Import words from csv file.

  1. Open the csv file

  2. Get the csv reader

  3. Skip the header

  4. For each row in the csv file

  5. Try to add the word to the database

  6. If the word already exists in the database with the same timestamp, increment the word_already_exists counter

  7. If the word does not exist in the database, increment the added_words counter

  8. If the csv file is not found, print an error message

Raises:

NoDataFoundException: If no words are found in the csv file.

vocabCLI.modules.NLP module#

vocabCLI.modules.NLP.censor_bad_words_not_strict(text: str) None[source]#

Removes the bad words from the text and replaces them with asterisks partially and prints the censor text

  1. First we check if the text is a URL, if yes, then we parse the text from it and then use the model

  2. If the text is not a URL, then we directly use the model

  3. Remove the punctuations and convert text to lowercase

  4. Read the bad words from the file and store them in a list

  5. Split the text into words and for each word, we check if it is a bad word, if yes, then we partially replace it with asterisks

  6. Print the censored text and the number of bad words censored

Args:

text (str): text that needs to be censored

vocabCLI.modules.NLP.censor_bad_words_strict(text: str) None[source]#

Removes the bad words from the text and replaces them with asterisks completely and prints the censor text

  1. First we check if the text is a URL, if yes, then we parse the text from it and then use the model

  2. If the text is not a URL, then we directly use the model

  3. Remove the punctuations and convert text to lowercase

  4. Read the bad words from the file and store them in a list

  5. Split the text into words and for each word, we check if it is a bad word, if yes, then we replace it with asterisks

  6. Print the censored text and the number of bad words censored

Args:

text (str): text that needs to be censored

vocabCLI.modules.NLP.check_url_or_text(value: str) bool[source]#

Checks if the value is a URL or a text

  1. Try to get the response from the URL, if we get a response, then it is a URL

  2. If we get an exception, then it is a text

Args:

value (str): URL or text to be checked

Returns:

bool: True if the value is a URL, False if the value is a text

Raises:

requests.exceptions.MissingSchema: If the URL is missing the schema requests.exceptions.InvalidSchema: If the URL has an invalid schema requests.exceptions.InvalidURL: If the URL is invalid

vocabCLI.modules.NLP.cleanup_text(text: str) str[source]#

Clean up the text by removing special characters, numbers, whitespaces, etc for further processing and to improve the accuracy of the model.

  1. Remove the non-ascii characters

  2. Remove the numbers

  3. Remove the whitespaces

  4. Remove the special characters except full stop and apostrophe

  5. Convert the text to lowercase

  6. Remove the leading and trailing whitespaces

  7. Split the text into words without messing up the punctuation

Args:

text (str): text to be cleaned up

Returns:

str: cleaned up text

vocabCLI.modules.NLP.extract_difficult_words(text: str) None[source]#

Extracts the difficult words from the text and prints them, uses the _most_common_words.txt file to determine the difficult words

  1. First we check if the text is a URL, if yes, then we parse the text from it and then use the model

  2. If the text is not a URL, then we directly use the model

  3. Open the file with a list of simple words (most common words used in English).

  4. Clean up the text from any unnecessary characters, full stops, and convert it to lowercase.

  5. Calculate the word count of the text.

  6. Create a list of difficult words by filtering out all words that are in the list of simple words.

  7. Remove some common words that are not in the list of simple words.

  8. Remove duplicate words.

  9. Remove plurals of the same word.

  10. Remove plurals of which singular is in the simple words list.

  11. Sort the list of difficult words.

  12. Print the word count and the number of difficult words.

  13. Print the list of difficult words in columns.

Args:

text (str): text/url to be analyzed

vocabCLI.modules.NLP.parse_text_from_web(webURL: str) str[source]#

Extracts the text from the main content of the web page. Removes the ads, comments, navigation bar, footer, html tags, etc

  1. Download the web page using trafilatura

  2. Extract the text from the downloaded web page using trafilatura

  3. Return the extracted text

Args:

webURL (str): URL of the web page

Returns:

str: clean text from the web page

Raises:

trafilatura.errors.FetchingError: If the URL is invalid or the server is down

vocabCLI.modules.NLP.readability_index(text: str) None[source]#

Prints the readability index of the text and the summary of the index

  1. First we check if the text is a URL, if yes, then we parse the text from it and then use the model

  2. If the text is not a URL, then we directly use the model

  3. Remove the punctuations and convert text to lowercase

  4. Split the text into words and count the number of words

  5. Split the text into sentences and count the number of sentences

  6. The function then calculates the readability index using the textstat module and stores it in the “readability_index” variable.

  7. Print the readability index and the summary of the index

Args:

text (str): text to be analyzed

vocabCLI.modules.NLP.sentiment_analysis(content: str) None[source]#

Performs sentiment analysis on the text and prints the sentiment score and the summary of the score

  1. Check if the content is a URL, if yes, then parse the text from it and then use the model

  2. If text and not URL, then directly use the model

3. Clean up the text from any unnecessary characters, full stops, and convert it to lowercase. 5. Load the tokenizer and model 6. Encode the text using the tokenizer 7. Send the encoded text to the model and get the result 8. Take the highest value from the result and convert it to a summary 9. Print the sentiment score and the summary

Args:

content (str): text/url to be analyzed

vocabCLI.modules.NLP.sentiment_score_to_summary(sentiment_score: int) str[source]#

Converts the sentiment score to a summary of the score

Args:

sentiment_score (int): sentiment score

Returns:

str: summary of the sentiment score

vocabCLI.modules.NLP.summarize_text(content: str, file: Optional[bool] = False) None[source]#

Print the summarized text or internet article.

  1. Check if the content is a URL or text

  2. If URL, then parse the text from it and then use the model

  3. If text, then directly use the model

  4. Clean up the text from any unnecessary characters, full stops, and convert it to lowercase.

  5. It summarizes the text using the summarize_text_util function.

  6. If the input is a URL, it prints the headline of the article as well.

  7. If the output is a file, it saves the summary to a file called summary.txt.

Args:

text (str): Text that is to be summarized

vocabCLI.modules.NLP.summarize_text_util(text: str, per: int) str[source]#

Summarizes the text using the spacy library

  1. Backend API call to OpenAI

  2. 😎 100% abstraction, GPT 3 does all the work

  3. Strip the text of any escape characters and newlines and return the summarized text

Args:

text (str): text to be summarized per (int): percentage of the text to be summarized

Returns:

str: summarized text

vocabCLI.modules.Quotes module#

vocabCLI.modules.Quotes.add_quote(quote: str, author: Optional[str] = None) None[source]#

Adds a quote to the database.

  1. The quote and author are stripped of any leading or trailing whitespace.

  2. The quote and author are checked to see if they are only whitespaces. If they are, an error message is printed and the function is returned.

  3. The quote and author are checked to see if they already exist in the database. If they do, an error message is printed and the function is returned.

  4. The quote and author are added to the database.

  5. A success message is printed.

Args:

quote (str): The quote to be added. author (str, optional): The author of the quote. Defaults to None.

vocabCLI.modules.Quotes.delete_all_quotes() None[source]#

Deletes all quotes from the database.

  1. Display a warning message & prompt the user to confirm the deletion

  2. Delete all quotes from the database

  3. Display a success message

vocabCLI.modules.Quotes.delete_quote() None[source]#

Deletes a quote from the database.

  1. Displays all the quotes in the database with their index using SELECT query

  2. If there are no quotes in the database, it raises a NoQuotesError

  3. Asks the user to select a quote to delete (by index)

  4. If the user enters a valid index, it deletes the quote from the database and prints a success message

  5. If the user enters an invalid index, it prints an error message

Raises:

NoQuotesError: If there are no quotes in the database

vocabCLI.modules.Quotes.get_quote_of_the_day() None[source]#

Get a random quote from a public API

  1. Gets a random quote from the API

  2. Prints the quote

vocabCLI.modules.Quotes.get_quotes() None[source]#

Returns a list of quotes from the database.

  1. Check if there are any quotes in the database

  2. If there are quotes, it prints a table with the quotes, authors and dates added

  3. If there are no quotes, it raises an exception

Raises:

NoQuotesError: If there are no quotes in the database.

vocabCLI.modules.Quotes.get_random_quote() None[source]#

Gets a random quote from the database.

  1. Displays a random quote from the database using SELECT query

  2. If there are no quotes in the database, it raises a NoQuotesError

  3. Prints the quote

Raises:

NoQuotesError: If there are no quotes in the database

vocabCLI.modules.Quotes.search_quote(quoteText: str) None[source]#

Searches for a quote in the database.

  1. It then strips the quote of any leading or trailing whitespace & removes the quotes from the quote if they exist

  2. It then converts the quote to lowercase so as to match the case of the quotes in the database

  3. It then checks if the quote does not only have whitespace

  4. If the quote does not only have whitespace, it then searches for the quote in the database while LOWERING all the quotes in the database

  5. If the quote does not exist, it prints an error message

  6. If the quote does exist, it prints a table with the search results

Args:

quoteText (str): The quote to be searched.

vocabCLI.modules.RSS module#

vocabCLI.modules.RSS.add_feed(url: str) None[source]#

Add the feed to the database

  1. Feed parser is used to parse the feed

  2. If the feed is not found, print error message

  3. Check if the feed exists in the database

  4. If it does not exist, add it to the database

  5. If it does exist, print error message

Args:

url (str): The URL of the feed

vocabCLI.modules.RSS.check_feed_for_new_content(title: str) None[source]#

Parse the feed and check for new content

  1. Check if the feed exists in the database

  2. If the feed does not exist, print error message

  3. If the feed exists, parse the feed and check for new content

  4. If new content is found, print the new content

  5. If no new content is found, print error message

Args:

title (str): Title of the feed

vocabCLI.modules.RSS.get_all_feeds() None[source]#

Get the feed details from the database

  1. Get all feeds from the database

  2. If no feeds exist, print error message

  3. Print the feeds in a table

vocabCLI.modules.RSS.remove_feed() None[source]#

Remove the feed from the database

  1. Get all feeds from the database

  2. If no feeds exist, print error message

  3. Print the feeds in a table

  4. Ask the user to select the feed to remove

  5. Remove the feed from the database

vocabCLI.modules.RSS.remove_html_tags(html: str) str[source]#

Remove html tags from a string

Args:

html (str): HTML string

vocabCLI.modules.Report module#

vocabCLI.modules.Report.generate_graph_report()[source]#

Generates a graph report

vocabCLI.modules.Report.generate_text_report()[source]#

Generates a text report

vocabCLI.modules.Spelling module#

vocabCLI.modules.Spelling.spell_checker(string: str) str[source]#

This function takes a string as input and returns a string with misspelled words highlighted in red.

  1. Split the string based on punctuation.

  2. Find those words that may be misspelled.

  3. Highlight the misspelled words in red.

  4. Return the string with misspelled words highlighted in red.

vocabCLI.modules.Study module#

vocabCLI.modules.Study.quiz_all(number: Optional[int] = None) None[source]#

Quiz all words in the database.

Args:

number: number of words to quiz, default is None.

vocabCLI.modules.Study.quiz_collection(number: Optional[int] = None, collectionName: Optional[str] = None) None[source]#

Quiz words in a collection.

Args:

number: number of words to quiz, default is None. collectionName: name of collection to quiz, default is None.

vocabCLI.modules.Study.quiz_favorite(number: Optional[int] = None) None[source]#

Quiz words in favorite list.

Args:

number: number of words to quiz, default is None.

vocabCLI.modules.Study.quiz_learning(number: Optional[int] = None) None[source]#

Quiz words in learning list.

Args:

number: number of words to quiz, default is None.

vocabCLI.modules.Study.quiz_mastered(number: Optional[int] = None) None[source]#

Quiz words in mastered list.

Args:

number: number of words to quiz, default is None.

vocabCLI.modules.Study.quiz_tag(number: Optional[int] = None, tag: Optional[str] = None) None[source]#

Quiz words with a specific tag.

Args:

number: number of words to quiz, default is None. tag: tag to quiz, default is None.

vocabCLI.modules.Study.revise_all(number: Optional[int] = None) None[source]#

Revise all words in the database.

  1. If number is not specified, then all words are revised.

  2. If number is specified, then only that many words are revised.

  3. If there are no words in the database, then an exception is raised.

Args:

number: number of words to revise, default is None.

Raises:

NoWordsInDBException: if there are no words in the database.

vocabCLI.modules.Study.revise_collection(number: Optional[int] = None, collectionName: Optional[str] = None) None[source]#

Revise words in a collection.

Args:

number: number of words to revise, default is None. collectionName: name of the collection, default is None.

vocabCLI.modules.Study.revise_favorite(number: Optional[int] = None) None[source]#

Revise words in favorite list.

Args:

number: number of words to revise, default is None.

vocabCLI.modules.Study.revise_learning(number: Optional[int] = None) None[source]#

Revise words in learning list.

Args:

number: number of words to revise, default is None.

vocabCLI.modules.Study.revise_mastered(number: Optional[int] = None) None[source]#

Revise words in mastered list.

Args:

number: number of words to revise, default is None.

vocabCLI.modules.Study.revise_tag(number: Optional[int] = None, tag: Optional[str] = None) None[source]#

Revise words in a specific tag.

Args:

number: number of words to revise, default is None. tag: tag to revise, default is None.

vocabCLI.modules.Study.show_quiz_history() None[source]#

Show quiz history.

  1. Execute SQL SELECT statement to get all the rows from the quiz_history table.

  2. If there are no rows, print a message and return.

  3. Else print the quiz history in a table.

vocabCLI.modules.Study.start_quiz(c: Cursor, collection=None, quizType: Optional[str] = None) None[source]#

Starts the quiz.

  1. Fetches all the words in the collection or in the database, depending on the quiz type.

  2. Breaks out if the collection has less than 4 words, as the minimum number of words in a quiz is 4.

  3. Sets the style of the quiz.

  4. Initializes the score and timer.

  5. Iterates over the words in the collection/database.

  6. Sets up the question.

  7. Fetches the correct answer for the question.

  8. Sets up the list of choices. If the quiz type is collection, the list of choices is made up of the correct answer and three fake answers from the collection. Otherwise, the list of choices is made up of the correct answer and three fake answers from the database.

  9. Asks the question to the user and checks if the answer is correct.

  10. If the answer is correct, increases the score and prints the success message. Otherwise, prints the failure message.

  11. Prints the quiz summary and inserts the quiz history into the database.

Args:

c: cursor object. type: type of the quiz. Must be one of “all words”, “learning words”, “mastered words”, “favorite words”, “collection: collectionName”, “tag:tagName”. collection: name of the collection, default is None.

vocabCLI.modules.Study.start_revision(c: Cursor, is_collection: bool = False) None[source]#

Starts the revision process.

  1. Fetches all the words in the collection from the database

  2. For each word in the collection, it prints out the word and its definition

  3. It asks the user if they want to set the word as learning

  4. If the user says yes, then the word is set as learning

  5. If the user says no, then the user is asked if they want to set the word as mastered

  6. If the user says yes, then the word is set as mastered

  7. If the user says no, then the user is asked if they want to stop revising

  8. If the user says yes, then the program stops revising, else it continues revising

Args:

c: cursor object is_collection: boolean to check if the revision is from a collection, default is False.

vocabCLI.modules.Thesaurus module#

vocabCLI.modules.Thesaurus.find_antonym(query: str) None[source]#

Finds the antonyms of the query word

  1. Connects to the API

  2. Checks if the API returned a response

  3. If it did, it loops through the response and adds the antonyms to a list

  4. If the list is empty, it uses the NLTK library to find antonyms

  5. If it still can’t find any antonyms, it prints an error message

  6. If it did find antonyms, it prints them in columns

Args:

query (str): Word to find antonyms for.

vocabCLI.modules.Thesaurus.find_synonym(query: str) None[source]#

Finds the synonyms of the query word

  1. Connects to the API

  2. Checks if the API returned a response

  3. If it did, it loops through the response and adds the synonyms to a list

  4. If the list is empty, it uses the NLTK library to find synonyms

  5. If it still can’t find any synonyms, it prints an error message

  6. If it did find synonyms, it prints them in columns

Args:

query (str): Word to find synonyms for.

vocabCLI.modules.Utils module#

vocabCLI.modules.Utils.add_tag(query: str, tagName: str) None[source]#

Tags the word in the vocabulary builder list.

  1. Check if the word exists in the database

  2. If the word does not exist in the database, raise an exception

  3. If the word exists in the database with no tags, then add the tag to add words

  4. If the word exists in the database with the same tag, then do nothing

  5. If the word exists in the database with a different tag, then overwrite the tag

  6. Print the success message

Args:

query (str): Word which is to be tagged. tagName (Optional[str], optional): Tag name which is to be added to the word and inserts it into the database. Defaults to None.

Raises:

WordNeverSearchedException: If the word is not found in the database

vocabCLI.modules.Utils.check_learning(query: str) bool[source]#

Checks if the word is learning and returns a boolean value.

  1. Check if the word exists in the database

  2. If the word does not exist in the database, raise an exception

  3. If the word exists in the database and learning is set to 1, then return True

  4. If the word exists in the database and learning is set to 0, then return False

Args:

query (str): word which is to be checked for learning status

Returns:

bool: True if the word is learning, False otherwise

vocabCLI.modules.Utils.check_mastered(query: str) bool[source]#

Checks if the word is mastered and returns a boolean value.

  1. Check if the word exists in the database

  2. If the word does not exist in the database, raise an exception

  3. If the word exists in the database and mastered is set to 1, then return True

  4. If the word exists in the database and mastered is set to 0, then return False

Args:

query (str): word which is to be checked for mastered status

Returns:

bool: True if the word is mastered, False otherwise

vocabCLI.modules.Utils.check_word_exists(query: str) bool[source]#

Checks if the word exists in the database

Args:

query (str): Word which is to be checked

Raises:

WordNeverSearchedException: If the word is not found in the database

Returns:

bool: True if word exists in the database

vocabCLI.modules.Utils.clear_all_words_from_tag(tagName: str) None[source]#

Clears all the words with specific tag.

Args:

tagName (str): The tag to clear words from.

Raises:

NoSuchTagException: If the tag doesn’t exist in the database.

vocabCLI.modules.Utils.clear_favorite() None[source]#

Clears all the words marked as favorite.

Raises:

NoWordsInFavoriteListException: If there are no words in the favorite list.

vocabCLI.modules.Utils.clear_learning() None[source]#

Clears all the words marked as learning.

Raises:

NoWordsInLearningListException: If there are no words in the learning list.

vocabCLI.modules.Utils.clear_mastered() None[source]#

Clears all the words marked as mastered.

Raises:

NoWordsInMasteredListException: If there are no words in the mastered list.

vocabCLI.modules.Utils.count_all_words() int[source]#

Counts the distinct number of words in the database.

Returns:

int: Total word count.

vocabCLI.modules.Utils.count_favorite() int[source]#

Counts the distinct number of favorite words in the database.

Returns:

int: Total favorite word count.

vocabCLI.modules.Utils.count_learning() int[source]#

Counts the distinct number of learning words in the database.

Returns:

int: Total learning word count.

vocabCLI.modules.Utils.count_mastered() int[source]#

Counts the distinct number of mastered words in the database.

Returns:

int: Total mastered word count.

vocabCLI.modules.Utils.count_tag(tag: str) int[source]#

Counts the distinct number of words in the database with a particular tag.

Returns:

int: Total word count of specific tag.

vocabCLI.modules.Utils.delete_all() None[source]#

Deletes all the words from the database.

Raises:

NoWordsInDBException: If there are no words in the database.

vocabCLI.modules.Utils.delete_favorite() None[source]#

Deletes all the favorite words from the database.

Raises:

NoWordsInFavoriteListException: If there are no favorite words in the database.

vocabCLI.modules.Utils.delete_learning() None[source]#

Deletes all the learning words from the database.

Raises:

NoWordsInLearningListException: If there are no learning words in the database.

vocabCLI.modules.Utils.delete_mastered() None[source]#

Deletes all the mastered words from the database.

Raises:

NoWordsInMasteredListException: If there are no mastered words in the database.

vocabCLI.modules.Utils.delete_word(query: List[str]) None[source]#

Deletes a word from the database.

Args:

query (str): Word to be deleted.

vocabCLI.modules.Utils.delete_words_from_tag(tag: str) None[source]#

Deletes all the words from a particular tag from the database.

Args:

tag (str): The tag to delete words from.

Raises:

NoSuchTagException: If the tag doesn’t exist in the database.

vocabCLI.modules.Utils.fetch_word_history(word: str) None[source]#

Fetches all instances of timestamp for a word from the database

  1. Execute a query that selects the datetime column from the words table where the word column is equal to the word

  2. If the word is not found in the database, raise an exception

  3. If the word is found in the database, print the history of the word

Args:

word (str): word for which history is to be fetched

Raises:

WordNeverSearchedException: If the word is not found in the database

vocabCLI.modules.Utils.get_consecutive_dates(dates: list) tuple[source]#

Returns list of consecutive dates from list of dates

  1. Sort the list of dates

  2. Iterate through the list of dates

  3. If the difference between the current date and the next date is 1 day, continue

  4. If the difference between the current date and the next date is not 1 day, append the start date and the current date to the list of consecutive dates

  5. Set the start date to the next date

  6. Return the item with the longest time difference

Args:

dates (list): list of dates

Returns:

tuple: tuple of consecutive dates

vocabCLI.modules.Utils.get_lookup_rate(today: bool = False, week: bool = False, month: bool = False, year: bool = False) None[source]#

Returns the learning rate of the user.

  1. If today, then get the number of words learned today, yesterday and the difference between them

  2. If week, then get the number of words learned this week, last week and the difference between them

  3. If month, then get the number of words learned this month, last month and the difference between them

  4. If year, then get the number of words learned this year, last year and the difference between them

  5. If no option is given, then print an error message

Args:

today (bool, optional): If True, returns the lookup rate for today. Defaults to False. week (bool, optional): If True, returns the lookup rate for the week. Defaults to False. month (bool, optional): If True, returns the lookup rate for the month. Defaults to False. year (bool, optional): If True, returns the lookup rate for the year. Defaults to False.

vocabCLI.modules.Utils.get_random_word_definition_from_api() None[source]#

Gets a random word from the text file and gets its definition from the API.

vocabCLI.modules.Utils.get_random_word_from_favorite_set() None[source]#

Gets a random word from the favorite list.

Raises:

NoWordsInFavoriteListException: If there are no words in the favorite list.

vocabCLI.modules.Utils.get_random_word_from_learning_set() None[source]#

Gets a random word from the learning list.

Raises:

NoWordsInLearningListException: If there are no words in the learning list.

vocabCLI.modules.Utils.get_random_word_from_mastered_set() None[source]#

Gets a random word with definition from the mastered words list.

Raises:

NoWordsInMasteredListException: If there are no words in the mastered list.

vocabCLI.modules.Utils.get_random_word_from_tag(tagName: str) None[source]#

Gets a random word from the vocabulary builder list with a particular tag. 1.

Args:

tag (Optional[str], optional): Tag from which the random word should be. Defaults to None.

Raises:

NoSuchTagException: If the tag does not exist.

vocabCLI.modules.Utils.predict_milestone(milestone: int) None[source]#

Predicts when user will reach a milestone

  1. It runs a query to get the number of words in the database.

  2. If there are no words in the database, it throws an exception and prints a message.

  3. If there are words in the database, it runs a query to get the date of the most recent word looked up (last_date).

  4. It then runs a query to get the date of the first word looked up (first_date).

  5. It calculates the average words per day.

  6. It calculates the date of reaching the milestone (milestone_date).

  7. It prints the average words per day, the number of words learnt, and the date of reaching the milestone

Parameters:

milestone (int): milestone to predict

vocabCLI.modules.Utils.remove_tag(query: str) None[source]#

Removes the tag from the word in the database

  1. Check if the word exists in the database

  2. If the word does not exist in the database, raise an exception

  3. If the word exists in the database with no tags, then do nothing

  4. If the word exists in the database with tags, then remove the tag

  5. Print the success message

Args:

query (str): Word for which the tag is to be removed

Raises:

WordNeverSearchedException: If the word is not found in the database

vocabCLI.modules.Utils.set_favorite(query: str) None[source]#

Sets the word as favorite.

  1. Check if the word exists in the database

  2. If the word does not exist in the database, raise an exception

  3. If the word exists in the database and favorite is set to 1, then do nothing

  4. If the word exists in the database and favorite is set to 0, then set it to 1

  5. Print the success message

Args:

query (str): Word which is to be set as favorite.

vocabCLI.modules.Utils.set_learning(query: str) None[source]#

Sets the word as learning.

  1. Check if the word exists in the database

  2. If the word does not exist in the database, raise an exception

  3. If the word exists in the database and is already learning, then do nothing

  4. If the word exists in the database and is mastered is set to 1, then set learning to 1 and mastered to 0

  5. If the word exists in the database and is mastered is set to 0, then set learning to 1

  6. Print the success message

Args:

query (str): Word which is to be set as learning.

vocabCLI.modules.Utils.set_mastered(query: str) None[source]#

Sets the word as mastered.

  1. Check if the word exists in the database

  2. If the word does not exist in the database, raise an exception

  3. If the word exists in the database and mastered is set to 1, then do nothing

  4. If the word exists in the database and learning is set to 1, then set mastered to 1 and learning to 0

  5. If the word exists in the database and mastered is set to 0, then set it to 1

  6. Print the success message

Args:

query (str): Word which is to be set as mastered.

Raises:

WordNeverSearchedException: If the word is not found in the database

vocabCLI.modules.Utils.set_unfavorite(query: str) None[source]#

Remove the word from favorite list.

  1. Check if the word exists in the database

  2. If the word does not exist in the database, raise an exception

  3. If the word exists in the database and favorite is set to 0, then do nothing

  4. If the word exists in the database and favorite is set to 1, then set it to 0

  5. Print the success message

Args:

query (str): Word which is to be removed from favorite.

vocabCLI.modules.Utils.set_unlearning(query: str) None[source]#

Sets the word as unlearning.

  1. Check if the word exists in the database

  2. If the word does not exist in the database, raise an exception

  3. If the word exists in the database and learning is set to 0, then do nothing

  4. If the word exists in the database and learning is set to 1, then set it 0

  5. Print the success message

Args:

query (str): Word which is to be set as unlearning.

vocabCLI.modules.Utils.set_unmastered(query: str) None[source]#

Sets the word as unmastered.

  1. Check if the word exists in the database

  2. If the word does not exist in the database, raise an exception

  3. If the word exists in the database and mastered is set to 0, then do nothing

  4. If the word exists in the database and mastered is set to 1, then set it as 0

  5. Print the success message

Args:

query (str): Word which is to be set as unmastered.

vocabCLI.modules.Utils.show_list(favorite: Optional[bool] = False, learning: Optional[bool] = False, mastered: Optional[bool] = False, tag: Optional[bool] = None, days: Optional[int] = None, date: Optional[str] = None, last: Optional[int] = None, most: Optional[int] = None, tagnames: Optional[bool] = False) None[source]#

Gets all the words in the vocabulary builder list.

  1. The code give a list of mastered, learning, favorite, words with a particular tag, most recent words, words added in a particular date or words added in the last n number of days or most recent words based on the arguments passed

2. Based on the arguments passed, the code executes the respective SQL command 1. If no arguments are passed, it gets all the words in the vocabulary builder list 4. If the SQL command returns no words, an error message is printed to the user 5. If the SQL command returns words, the words are printed to the user in a table format

Args:

favorite (bool, optional): If True, gets list of favorite words. Defaults to False. learning (bool, optional): If True, gets list of learning words. Defaults to False. mastered (bool, optional): If True, gets list of mastered words. Defaults to False. tag (string, optional): Gets the list of words of the mentioned tag. Defaults to None. days (int, optional): Get a list of words from last n number of days. Defaults to None. date (string, optional): Get a list of words from a particular date. Defaults to None. last (string, optional):”Get a list of n last searched words. Defaults to None. most (string, optional): Get a list of n most searched words. Defaults to None. tagnames (bool, optional): If True, gets list of all tags. Defaults to False.

vocabCLI.modules.Utils.show_streak() None[source]#

Shows streak of days user has looked up words

  1. Check if there are any words in the database.

  2. If there are words, get all the dates from the database.

  3. Convert dates to datetime objects

  4. Sort dates

  5. Get consecutive dates

  6. Get difference between consecutive dates

  7. Print streak

vocabCLI.modules.WordCollections module#

vocabCLI.modules.WordCollections.clean_collection_csv_data()[source]#

Cleans the domains.csv file and writes the cleaned data to domains.csv

vocabCLI.modules.WordCollections.delete_collection_from_DB()[source]#

Deletes all rows from the collections table

vocabCLI.modules.WordCollections.get_random_word_from_collection(collectionName: str)[source]#

Shows a random word from a collection

Args:

collectionName (str): Name of the collection

Raises:

NoSuchCollectionException: If the collection does not exist

vocabCLI.modules.WordCollections.insert_collection_to_DB()[source]#

Inserts the cleaned data from domains.csv to the collections table in the database if the table is empty

vocabCLI.modules.WordCollections.show_all_collections()[source]#

Shows all the collections in the database

vocabCLI.modules.WordCollections.show_words_from_collection(collectionName: str)[source]#

Shows all the words in a collection

Args:

collectionName (str): Name of the collection

Raises:

NoSuchCollectionException: If the collection does not exist

Module contents#