Changes Made for Improved Code Quality #2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bhagavad Gita Verse Generator
This Python script generates random verses from the Bhagavad Gita and displays them in a formatted manner. The script utilizes web scraping techniques to extract verses from the Holy Bhagavad Gita website.
Changes Made for Improved Code Quality
1. Dictionary for Verse Ranges
To enhance code readability and maintainability, a dictionary named
VERSE_RANGES
is introduced. It stores the maximum number of verses for each chapter, replacing the previous if-elif statements. This change simplifies the logic and allows for easy updates.2. Formatted String Literal (f-string)
In the
generate_link
function, f-strings are used for formatting the link. This makes the code concise and more readable.3. Refactored
get_p
FunctionThe
get_p
function is renamed tomain
for better clarity. Additionally, the handling of paragraphs in the scraped HTML is improved for better readability.4. Variable Naming and Comments
Variable names are updated for better readability, and comments are added to explain the purpose of certain code blocks. This makes the code more understandable for developers.
5. Handling Missing Element
The code now checks if the element with id "transliteration_wo_dia" exists before attempting to extract paragraphs. This prevents potential issues if the element is not present on the webpage.
6. Formatted Print Statement
The print statement at the end is formatted using an f-string for better readability.
How to Use
pip install -r requirements.txt
.python bhagavad_gita_verse_generator.py
.Feel free to explore and customize the script as needed. Enjoy exploring the wisdom of the Bhagavad Gita!