AnnNaser commited on
Commit
d58b538
·
verified ·
1 Parent(s): f877db8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -3
app.py CHANGED
@@ -56,9 +56,6 @@ def fetch_book_details(book_key: str) -> Dict:
56
  if response.status_code == 200:
57
  book_data = response.json()
58
 
59
- # Debugging statements to inspect the API response
60
- st.write(f"Book Data: {book_data}")
61
-
62
  # Get Title
63
  title = book_data.get("title", "N/A")
64
 
@@ -95,6 +92,18 @@ def fetch_book_details(book_key: str) -> Dict:
95
  st.error(f"Failed to fetch details for book: {book_key}")
96
  return None
97
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  # Streamlit App
99
  def main():
100
  st.title("📚 Book Recommendation System")
 
56
  if response.status_code == 200:
57
  book_data = response.json()
58
 
 
 
 
59
  # Get Title
60
  title = book_data.get("title", "N/A")
61
 
 
92
  st.error(f"Failed to fetch details for book: {book_key}")
93
  return None
94
 
95
+ # Function to scrape book description from OpenLibrary
96
+ @st.cache_data(ttl=3600)
97
+ def scrape_book_description(book_key: str) -> str:
98
+ response = requests.get(f"https://openlibrary.org{book_key}")
99
+ if response.status_code == 200:
100
+ soup = BeautifulSoup(response.text, 'html.parser')
101
+ description_div = soup.find("div", class_="read-more__content")
102
+ if description_div:
103
+ paragraphs = description_div.find_all('p')
104
+ return " ".join(paragraph.get_text(strip=True) for paragraph in paragraphs)
105
+ return "N/A"
106
+
107
  # Streamlit App
108
  def main():
109
  st.title("📚 Book Recommendation System")