Skip to content

Commit

Permalink
fix pylint
Browse files Browse the repository at this point in the history
  • Loading branch information
lawrieb committed Mar 13, 2024
1 parent 993f85e commit 963bfa7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 33 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/build_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,12 @@ jobs:
# If there are any other steps in order for your tests to
# run successfully, you can add those steps here!

# # Next step: run pylint. Anything less than 10/10 will fail.
# - name: Lint with pylint
# run: |
# pylint bookworm/*.py
# pylint bookworm/**/*.py
# Next step: run pylint. Anything less than 10/10 will fail.
- name: Lint with pylint
run: |
pylint bookworm/*.py
pylint bookworm/**/*.py
# Next step: run the unit tests with code coverage.
- name: Unit tests
Expand Down
58 changes: 31 additions & 27 deletions bookworm/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@
FUNCTIONS
========
display_avg_ratings_slider():
Displays average ratings slider; returns input.
Displays average ratings slider; returns input.
display_num_ratings_slider():
Displays slider for number of ratings; returns input.
Displays slider for number of ratings; returns input.
display_search_mode_ui():
Displays text box for user to enter desired search method; returns input.
Displays text box for user to enter desired search method; returns input.
display_search_value_ui(search_mode):
Displays text box for user to enter query to search; retrieves user input.
Displays text box for user to enter query to search; retrieves user input.
display_genre_dropdown():
Displays drop down menu for genre selection; retrieves value; returns input.
Displays drop down for genre selection; retrieves value; returns input.
main()
Displays UI; gathers user feedback; executes serach.
Expand All @@ -26,7 +26,8 @@

import base64
import streamlit as st
#import streamlit.components.v1 as components

# import streamlit.components.v1 as components
try:
from search_wrapper import search_wrapper
except ImportError:
Expand All @@ -41,6 +42,7 @@
page_icon=":books:", # Icon for the page
)


# Define CSS for styling
def local_css(file_name):
"""
Expand All @@ -49,6 +51,7 @@ def local_css(file_name):
with open(file_name, encoding='utf-8') as f:
st.markdown(f'<style>{f.read()}</style>', unsafe_allow_html=True)


try:
local_css("styles.css") # Load custom CSS
except FileNotFoundError:
Expand All @@ -74,6 +77,7 @@ def local_css(file_name):
"History", "Philosophy", "Science"
]


# DEFINE EACH UI ELEMENT AS A SEPARATE FUNCTION
def display_avg_ratings_slider():
"""
Expand All @@ -87,6 +91,7 @@ def display_avg_ratings_slider():
value=0.0, step=0.5, key="Ave. Ratings Slider",
help="Set the minimum average rating.")


def display_num_ratings_slider():
"""
Displays slider for number of ratings; returns user input.
Expand All @@ -97,8 +102,9 @@ def display_num_ratings_slider():
"""
return st.slider("Exclude Books that have been rated by fewer than:",
min_value=0, max_value=50,
value=0, step=1, key="Num. Ratings Slider",
help="Set the minimum number of ratings.")
value=0, step=1, key="Num. Ratings Slider",
help="Set the minimum number of ratings.")


def display_search_mode_ui():
"""
Expand All @@ -120,9 +126,10 @@ def display_search_mode_ui():

return search_mode


def display_search_value_ui(search_mode):
""" Display text box for user to enter query to search; returns input.
Return value
User's search query, as a string.
"""
Expand All @@ -133,12 +140,13 @@ def display_search_value_ui(search_mode):
if display_str in ["Author1", "Author2"]:
display_str = display_str[:-1]
return st.text_input(f"Input your favorite {display_str}",
key="search_val")
key="search_val")


def display_genre_dropdown():
"""
Displays drop down menu for genre selection; returns user input.
Return value
User's genre selection as a string.
"""
Expand All @@ -149,52 +157,49 @@ def display_genre_dropdown():
return st.text_input("Describe your favorite genre", key="other_genre")
return genre_pick


def display_search_button(disabled=False):
"""
Displays button to initate search.
Displays button to initate search.
Return value
Boolean indicating whether user has clicked search.
Boolean indicating whether user has clicked search.
"""
return st.button("Search Now", key="search_now",
help="Click to initiate search.", type="primary",
disabled=disabled, use_container_width=False)


def main():
"""
"""
Displays UI; gathers user feedback; executes serach.
"""

# Display header banner with stock image of books
st.image("images/books_banner.png", use_column_width=True)

title_image = "images/butterfly.png"

with open(title_image, "rb") as file:
image_data = base64.b64encode(file.read()).decode()


st.markdown(
f"""
<div class="container">
<img class="title-img" src="data:image/png;base64,
{base64.b64encode(open(title_image, "rb").read()).decode()}">
<img class="title-img" src="data:image/png;base64, {image_data}">
<p class="title-text">The Bookish Butterfly</p>
</div>
""",
unsafe_allow_html=True
)


# Add introductory text
st.write("Welcome to The Bookish Butterfly! A literary guide designed for"
"bookworms, aiding in the exploration of new books with tailored"
"preferences. Simply choose how you want to prioritize your"
"search, input your favorite book, author, plot, or genre. "
"Adjust the search filters as desired, and click 'Search Now'"
"to find your next literary adventure.")
"bookworms, aiding in the exploration of new books with tailored"
"preferences. Simply choose how you want to prioritize your"
"search, input your favorite book, author, plot, or genre. "
"Adjust the search filters as desired, and click 'Search Now'"
"to find your next literary adventure.")

# Display search mode, value, and button
search_mode = display_search_mode_ui()
Expand All @@ -205,8 +210,6 @@ def main():
min_ave_rating = display_avg_ratings_slider()
min_num_ratings = display_num_ratings_slider()



if search_val not in ["", None]:
search_button = display_search_button()
if not search_button:
Expand All @@ -222,4 +225,5 @@ def main():
except ValueError as e:
st.write(f"{str(e)}")


main()

0 comments on commit 963bfa7

Please sign in to comment.