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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -50,11 +50,13 @@ def search_for_books(author: str) -> list[dict[str,str]]:
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'],
@@ -65,6 +67,10 @@ def search_for_books(author: str) -> list[dict[str,str]]:
65
  results.append(book_info)
66
 
67
  counter+=1
 
 
 
 
68
 
69
  return results
70
 
 
50
  params = {"search": author}
51
  base_url = 'https://gutendex.com/books'
52
 
53
+ response = requests.get(base_url, params=params)
54
+ json_data = response.json()
55
+
56
  results = []
57
+ while json_data['next']:
58
+ print(counter)
59
+
60
  for book in json_data['results']:
61
  book_info = {
62
  'title': book['title'],
 
67
  results.append(book_info)
68
 
69
  counter+=1
70
+ if counter >= max_pages:
71
+ break
72
+ response = requests.get(json_data['next'])
73
+ json_data = response.json()
74
 
75
  return results
76