vocabCLI.modules package#
Submodules#
vocabCLI.modules.About module#
- vocabCLI.modules.About.print_about_app() None [source]#
Prints the about app page
Create a layout object
Create a header content object with the help of the Panel class
Create a footer content object with the help of the Panel class
Create a main content object with the help of the Panel class
Divide the “screen” into three parts
Update the header, main and footer with their respective content objects
Print the layout which contains details about the app
vocabCLI.modules.Banner module#
vocabCLI.modules.Carousel module#
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]#
Creates the tables in the database if they do not exist
Tables created are words, cache_words, collections, quiz_history, quotes, rss
The tables are created using the SQL statements in the docstring with respective column names and data types
The tables are created using the execute method of the connection object
The connection object is passed as an argument to the function
- Args:
conn (sqlite3.Connection): Connection object
- vocabCLI.modules.Database.refresh_cache() None [source]#
Refreshes the cache of the words in the database.
Connect to the database
Check if the cache is empty, if yes, then do nothing.
If the cache is not empty, then we need to refresh it.
Get all the words from the cache.
For each word, get the response from the API and update the cache.
If there’s an error, then show a error message and exit.
If there’s no error, then update the cache.
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.
Connect to the internet to check if the word is a valid word.
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.
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.
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.
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.
The function definition then calls the function phonetic which takes query (str) as argument and returns the phonetic (str) of the word.
The function definition then calls the function insert_word_to_db which takes query (str) as argument and inserts the word into the database.
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.
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.
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.
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
Create a connection to the database
Create a cursor to execute SQL queries on the database
Execute an SQL query that returns the collection name for a given word
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.
Get the API key from the environment variables
Send a GET request to the Wordnik API to get the word of the day
Get the word from the response
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.
If the word exists in the database, with a tag, then insert it with that tag.
If the word exists in the database, without a tag, then insert it without a tag.
If the word exists in the database, with favorite 1, then insert it with favorite 1.
If the word exists in the database, with learning 1, then insert it with learning 1.
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.
It takes the query as an argument.
It connects to the API and retrieves the response.
If the word is not found in the dictionary, it prints the message.
If the word is found, it loops through the phonetics.
If the phonetic is available, it returns it.
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.
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.
The function say_aloud then checks if the audio is available or not.
If the audio is available, the function say_aloud then downloads the audio file and plays it.
If the audio is not available, the function say_aloud then raises the AudioUnavailableException.
The function say_aloud then deletes the audio file.
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
Open the commonly_confused.csv file
Read the file
If the word is in the row, then print the words in the row as commonly confused words
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#
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.
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.
Execute a query that selects the api_response column from the cache_words table where the word column is equal to the query
Load the api_response column as a JSON object
Create an empty dictionary
Loop through each meaning in the meanings array
For each meaning, loop through the first 3 definitions
For each definition, add it to the dictionary with the key being the definition and the value being the example if it exists
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.
It calculates the difference between the two colors
It divides the difference by the number of steps
It adds the difference to the black color each time it moves one step
It returns the new color, rounded to the nearest integer
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.
Count number of words in learning and mastered.
Set the style of the graph.
Plot a pie chart.
Export the graph as png.
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.
Get the top N tags and their word count from the database and store them in a list
If no words are found, print an error message and return
If there are less words than the number we want to display, print a warning message
Create a dataframe from the list
Set the style of the graph
Plot the graph
Export the graph to a png file
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.
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.
If no words are found, print an error message and return
If there are less words than the number we want to display, print a warning message
Create a dataframe from the list of tags and the list of counts.
Set the theme of the plot.
Create a pie chart using the dataframe.
Save the plot in a file.
Check if the directory exists, if not create it.
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
Get the top N words and their word count from the database and store them in a list
If no words are found, print an error message and return
If there are less words than the number we want to display, print a warning message
Create a dataframe from the list
Set the style of the graph
Plot the graph
Export the graph to a png file
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.
Create a cursor and execute a query to fetch the word and the count of the word from the database
If no words are found, print an error message and return
If there are less words than the number we want to display, print a warning message
Create a dataframe using the top words and their counts
Create a pie chart using matplotlib and seaborn and save it to a file
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.
Selects the collection column and the word count from the words and collections table.
Creates a dataframe from the data obtained.
Sets the style of the graph.
Creates a bar graph based on the dataframe.
Saves the graph to the exports folder.
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.
- Get the data from the function word_distribution_month_util() which is a list of:
Dates
Word count
Create a dataframe from the list
Set the style of the graph
Plot the graph
Set the graph title, x and y axis labels, and x axis tick labels
Save the graph to the folder ‘exports’
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.
Create a dataframe from a list of tuples (day, count).
Set the style of the graph.
Plot the graph with the dataframe.
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.word_distribution_month_util() tuple[list, list] [source]#
Returns the distribution of word by dates of month.
Determine current year, current month and next month.
Determine total number of days in current month.
Get unformatted datestrings for each day in current month.
Get word count for each day in current month.
- Returns:
list: List of dates of month. list: List of word counts.
- vocabCLI.modules.Graph.words_distribution_week_util() tuple[list, list] [source]#
Returns the distribution of words by day of the week.
Create a dictionary with numbers as keys and weekdays as values.
Create two lists, one for weekdays and one for word count.
Query the database for word count for each day in the current week.
Loop through the results and assign the weekday to the list.
Assign the word count to the list.
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
Page footer.
- vocabCLI.modules.ImportExport.export_to_csv() None [source]#
Export words to csv file.
Create a connection to the database.
Create a cursor object.
Execute a SELECT query to fetch all the words from the database.
Write the words to a csv file.
Execute a SELECT query to fetch all the quotes from the database.
Write the quotes to a csv file.
Execute a SELECT query to fetch all the rss feeds from the database.
Write the rss feeds to a csv file.
Execute a SELECT query to fetch all the quiz history from the database.
Write the quiz history to a csv file.
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.
Create a pdf file
Sets all the attributes (colour, font, size, etc.)
Execute a query to select all words from the database
If there are no rows, raise NoDataFoundException
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.
Open the csv file
Get the csv reader
Skip the header
For each row in the csv file
Try to add the word to the database
If the word already exists in the database with the same timestamp, increment the word_already_exists counter
If the word does not exist in the database, increment the added_words counter
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
First we check if the text is a URL, if yes, then we parse the text from it and then use the model
If the text is not a URL, then we directly use the model
Remove the punctuations and convert text to lowercase
Read the bad words from the file and store them in a list
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
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
First we check if the text is a URL, if yes, then we parse the text from it and then use the model
If the text is not a URL, then we directly use the model
Remove the punctuations and convert text to lowercase
Read the bad words from the file and store them in a list
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
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
Try to get the response from the URL, if we get a response, then it is a URL
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.
Remove the non-ascii characters
Remove the numbers
Remove the whitespaces
Remove the special characters except full stop and apostrophe
Convert the text to lowercase
Remove the leading and trailing whitespaces
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
First we check if the text is a URL, if yes, then we parse the text from it and then use the model
If the text is not a URL, then we directly use the model
Open the file with a list of simple words (most common words used in English).
Clean up the text from any unnecessary characters, full stops, and convert it to lowercase.
Calculate the word count of the text.
Create a list of difficult words by filtering out all words that are in the list of simple words.
Remove some common words that are not in the list of simple words.
Remove duplicate words.
Remove plurals of the same word.
Remove plurals of which singular is in the simple words list.
Sort the list of difficult words.
Print the word count and the number of difficult words.
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
Download the web page using trafilatura
Extract the text from the downloaded web page using trafilatura
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
First we check if the text is a URL, if yes, then we parse the text from it and then use the model
If the text is not a URL, then we directly use the model
Remove the punctuations and convert text to lowercase
Split the text into words and count the number of words
Split the text into sentences and count the number of sentences
The function then calculates the readability index using the textstat module and stores it in the “readability_index” variable.
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
Check if the content is a URL, if yes, then parse the text from it and then use the model
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.
Check if the content is a URL or text
If URL, then parse the text from it and then use the model
If text, then directly use the model
Clean up the text from any unnecessary characters, full stops, and convert it to lowercase.
It summarizes the text using the summarize_text_util function.
If the input is a URL, it prints the headline of the article as well.
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
Backend API call to OpenAI
😎 100% abstraction, GPT 3 does all the work
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.
The quote and author are stripped of any leading or trailing whitespace.
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.
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.
The quote and author are added to the database.
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.
Display a warning message & prompt the user to confirm the deletion
Delete all quotes from the database
Display a success message
- vocabCLI.modules.Quotes.delete_quote() None [source]#
Deletes a quote from the database.
Displays all the quotes in the database with their index using SELECT query
If there are no quotes in the database, it raises a NoQuotesError
Asks the user to select a quote to delete (by index)
If the user enters a valid index, it deletes the quote from the database and prints a success message
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
Gets a random quote from the API
Prints the quote
- vocabCLI.modules.Quotes.get_quotes() None [source]#
Returns a list of quotes from the database.
Check if there are any quotes in the database
If there are quotes, it prints a table with the quotes, authors and dates added
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.
Displays a random quote from the database using SELECT query
If there are no quotes in the database, it raises a NoQuotesError
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.
It then strips the quote of any leading or trailing whitespace & removes the quotes from the quote if they exist
It then converts the quote to lowercase so as to match the case of the quotes in the database
It then checks if the quote does not only have whitespace
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
If the quote does not exist, it prints an error message
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
Feed parser is used to parse the feed
If the feed is not found, print error message
Check if the feed exists in the database
If it does not exist, add it to the database
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
Check if the feed exists in the database
If the feed does not exist, print error message
If the feed exists, parse the feed and check for new content
If new content is found, print the new content
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
Get all feeds from the database
If no feeds exist, print error message
Print the feeds in a table
vocabCLI.modules.Report module#
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.
Split the string based on punctuation.
Find those words that may be misspelled.
Highlight the misspelled words in red.
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.
If number is not specified, then all words are revised.
If number is specified, then only that many words are revised.
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.
Execute SQL SELECT statement to get all the rows from the quiz_history table.
If there are no rows, print a message and return.
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.
Fetches all the words in the collection or in the database, depending on the quiz type.
Breaks out if the collection has less than 4 words, as the minimum number of words in a quiz is 4.
Sets the style of the quiz.
Initializes the score and timer.
Iterates over the words in the collection/database.
Sets up the question.
Fetches the correct answer for the question.
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.
Asks the question to the user and checks if the answer is correct.
If the answer is correct, increases the score and prints the success message. Otherwise, prints the failure message.
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.
Fetches all the words in the collection from the database
For each word in the collection, it prints out the word and its definition
It asks the user if they want to set the word as learning
If the user says yes, then the word is set as learning
If the user says no, then the user is asked if they want to set the word as mastered
If the user says yes, then the word is set as mastered
If the user says no, then the user is asked if they want to stop revising
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
Connects to the API
Checks if the API returned a response
If it did, it loops through the response and adds the antonyms to a list
If the list is empty, it uses the NLTK library to find antonyms
If it still can’t find any antonyms, it prints an error message
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
Connects to the API
Checks if the API returned a response
If it did, it loops through the response and adds the synonyms to a list
If the list is empty, it uses the NLTK library to find synonyms
If it still can’t find any synonyms, it prints an error message
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.
Check if the word exists in the database
If the word does not exist in the database, raise an exception
If the word exists in the database with no tags, then add the tag to add words
If the word exists in the database with the same tag, then do nothing
If the word exists in the database with a different tag, then overwrite the tag
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.
Check if the word exists in the database
If the word does not exist in the database, raise an exception
If the word exists in the database and learning is set to 1, then return True
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.
Check if the word exists in the database
If the word does not exist in the database, raise an exception
If the word exists in the database and mastered is set to 1, then return True
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
Execute a query that selects the datetime column from the words table where the word column is equal to the word
If the word is not found in the database, raise an exception
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
Sort the list of dates
Iterate through the list of dates
If the difference between the current date and the next date is 1 day, continue
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
Set the start date to the next date
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.
If today, then get the number of words learned today, yesterday and the difference between them
If week, then get the number of words learned this week, last week and the difference between them
If month, then get the number of words learned this month, last month and the difference between them
If year, then get the number of words learned this year, last year and the difference between them
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
It runs a query to get the number of words in the database.
If there are no words in the database, it throws an exception and prints a message.
If there are words in the database, it runs a query to get the date of the most recent word looked up (last_date).
It then runs a query to get the date of the first word looked up (first_date).
It calculates the average words per day.
It calculates the date of reaching the milestone (milestone_date).
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
Check if the word exists in the database
If the word does not exist in the database, raise an exception
If the word exists in the database with no tags, then do nothing
If the word exists in the database with tags, then remove the tag
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.
Check if the word exists in the database
If the word does not exist in the database, raise an exception
If the word exists in the database and favorite is set to 1, then do nothing
If the word exists in the database and favorite is set to 0, then set it to 1
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.
Check if the word exists in the database
If the word does not exist in the database, raise an exception
If the word exists in the database and is already learning, then do nothing
If the word exists in the database and is mastered is set to 1, then set learning to 1 and mastered to 0
If the word exists in the database and is mastered is set to 0, then set learning to 1
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.
Check if the word exists in the database
If the word does not exist in the database, raise an exception
If the word exists in the database and mastered is set to 1, then do nothing
If the word exists in the database and learning is set to 1, then set mastered to 1 and learning to 0
If the word exists in the database and mastered is set to 0, then set it to 1
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.
Check if the word exists in the database
If the word does not exist in the database, raise an exception
If the word exists in the database and favorite is set to 0, then do nothing
If the word exists in the database and favorite is set to 1, then set it to 0
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.
Check if the word exists in the database
If the word does not exist in the database, raise an exception
If the word exists in the database and learning is set to 0, then do nothing
If the word exists in the database and learning is set to 1, then set it 0
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.
Check if the word exists in the database
If the word does not exist in the database, raise an exception
If the word exists in the database and mastered is set to 0, then do nothing
If the word exists in the database and mastered is set to 1, then set it as 0
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.
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
Check if there are any words in the database.
If there are words, get all the dates from the database.
Convert dates to datetime objects
Sort dates
Get consecutive dates
Get difference between consecutive dates
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