Matty-Sam commited on
Commit
d0f7b39
·
verified ·
1 Parent(s): c3dc79c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -8
app.py CHANGED
@@ -43,18 +43,18 @@ def search_for_books(author: str) -> list[dict[str,str]]:
43
  Returns:
44
  List of dictionaries. Each list item is a book and dictionaries have keys 'title', 'authors', 'subjects', and 'summaries'
45
  """
46
-
 
 
47
  try:
48
  params = {"search": author}
49
  base_url = 'https://gutendex.com/books'
50
- response = requests.get(base_url, params=params)
51
-
52
- if response and response.status_code != 200:
53
- return f"Error fetching book data for 'search term: {search_term}'"
54
 
55
- json_data = response.json()
56
  results = []
57
- while json_data['next']:
 
 
58
  for book in json_data['results']:
59
  book_info = {
60
  'title': book['title'],
@@ -63,7 +63,8 @@ def search_for_books(author: str) -> list[dict[str,str]]:
63
  'summaries': book['summaries']
64
  }
65
  results.append(book_info)
66
- response = requests.get(json_data['next'])
 
67
 
68
  return results
69
 
 
43
  Returns:
44
  List of dictionaries. Each list item is a book and dictionaries have keys 'title', 'authors', 'subjects', and 'summaries'
45
  """
46
+
47
+ max_pages = 5
48
+ counter = 0
49
  try:
50
  params = {"search": author}
51
  base_url = 'https://gutendex.com/books'
 
 
 
 
52
 
53
+ json_data = {'next': True}
54
  results = []
55
+ while json_data['next'] and counter < max_pages:
56
+ response = requests.get(json_data['next'])
57
+ json_data = response.json()
58
  for book in json_data['results']:
59
  book_info = {
60
  'title': book['title'],
 
63
  'summaries': book['summaries']
64
  }
65
  results.append(book_info)
66
+
67
+ counter+=1
68
 
69
  return results
70