AnnNaser commited on
Commit
6004b99
·
verified ·
1 Parent(s): 6788d83

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -9
app.py CHANGED
@@ -7,15 +7,23 @@ def fetch_books(subject, start_year, end_year):
7
  query = f"subject:{subject}"
8
  params = {
9
  "q": query,
10
- "first_publish_year": f"[{start_year} TO {end_year}]"
 
11
  }
12
- response = requests.get(base_url, params=params)
13
- print(f"API URL: {response.url}") # Debugging: Print the full API URL
14
- print(f"Status Code: {response.status_code}") # Debugging: Print the status code
15
- if response.status_code == 200:
16
- return response.json().get("docs", [])
17
- else:
18
- st.error(f"Failed to fetch data from Open Library API. Status Code: {response.status_code}")
 
 
 
 
 
 
 
19
  return []
20
 
21
  # Streamlit App
@@ -52,4 +60,4 @@ def main():
52
 
53
  # Run the app
54
  if __name__ == "__main__":
55
- main()
 
7
  query = f"subject:{subject}"
8
  params = {
9
  "q": query,
10
+ "first_publish_year": f"{start_year}",
11
+ "last_publish_year": f"{end_year}"
12
  }
13
+
14
+ try:
15
+ response = requests.get(base_url, params=params)
16
+ response.raise_for_status() # Will raise an exception for status codes 4xx/5xx
17
+ print(f"API URL: {response.url}") # Debugging: Print the full API URL
18
+ print(f"Status Code: {response.status_code}") # Debugging: Print the status code
19
+
20
+ if response.status_code == 200:
21
+ return response.json().get("docs", [])
22
+ else:
23
+ st.error(f"Failed to fetch data from Open Library API. Status Code: {response.status_code}")
24
+ return []
25
+ except requests.exceptions.RequestException as e:
26
+ st.error(f"Error fetching data from Open Library API: {e}")
27
  return []
28
 
29
  # Streamlit App
 
60
 
61
  # Run the app
62
  if __name__ == "__main__":
63
+ main()