mtoft20 commited on
Commit
cb28927
Β·
verified Β·
1 Parent(s): d8790e9

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +69 -17
src/streamlit_app.py CHANGED
@@ -50,19 +50,36 @@ def get_netflix_content():
50
  return []
51
 
52
  headers = {"xc-token": api_token}
 
 
 
53
 
54
  try:
55
- response = requests.get(
56
- f"{NOCODB_URL}{endpoint_path}?limit=1000",
57
- headers=headers
58
- )
59
-
60
- if response.status_code == 200:
61
- data = response.json()
62
- return data.get('list', [])
63
- else:
64
- st.error(f"Failed to fetch data: {response.status_code}")
65
- return []
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
 
67
  except Exception as e:
68
  st.error(f"Error connecting to database: {e}")
@@ -286,9 +303,29 @@ def main():
286
  st.subheader(f"πŸ“‹ Found {len(filtered_content)} Titles")
287
 
288
  if filtered_content:
289
- # Show first 10 items
290
- for i, content in enumerate(filtered_content[:10]):
291
- with st.expander(f"{content.get('title', 'N/A')} ({content.get('release_year', 'N/A')})"):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
292
  # Content details in columns
293
  detail_col1, detail_col2 = st.columns(2)
294
 
@@ -299,15 +336,30 @@ def main():
299
 
300
  with detail_col2:
301
  st.write(f"**🎬 Genre:** {content.get('listed_in', 'N/A')}")
302
- st.write(f"**πŸ‘₯ Cast:** {content.get('cast', 'N/A')[:100]}...")
 
 
 
303
  st.write(f"**πŸ“ Director:** {content.get('director', 'N/A')}")
304
 
305
  # Description
306
  st.write(f"**πŸ“– Description:**")
307
  st.write(content.get('description', 'N/A'))
308
 
309
- if len(filtered_content) > 10:
310
- st.info(f"Showing first 10 of {len(filtered_content)} titles. Adjust filters to narrow results.")
 
 
 
 
 
 
 
 
 
 
 
 
311
  else:
312
  st.info("No content matches your current filters. Try adjusting the criteria.")
313
 
 
50
  return []
51
 
52
  headers = {"xc-token": api_token}
53
+ all_content = []
54
+ page = 1
55
+ page_size = 1000 # Maximum allowed by NocoDB
56
 
57
  try:
58
+ while True:
59
+ offset = (page - 1) * page_size
60
+ response = requests.get(
61
+ f"{NOCODB_URL}{endpoint_path}?limit={page_size}&offset={offset}",
62
+ headers=headers
63
+ )
64
+
65
+ if response.status_code == 200:
66
+ data = response.json()
67
+ current_page_content = data.get('list', [])
68
+
69
+ if not current_page_content: # No more records
70
+ break
71
+
72
+ all_content.extend(current_page_content)
73
+ page += 1
74
+
75
+ # Show progress
76
+ st.write(f"Fetched {len(all_content)} records...")
77
+ else:
78
+ st.error(f"Failed to fetch data: {response.status_code}")
79
+ break
80
+
81
+ st.write(f"Total records fetched: {len(all_content)}")
82
+ return all_content
83
 
84
  except Exception as e:
85
  st.error(f"Error connecting to database: {e}")
 
303
  st.subheader(f"πŸ“‹ Found {len(filtered_content)} Titles")
304
 
305
  if filtered_content:
306
+ # Add pagination controls
307
+ items_per_page = st.select_slider(
308
+ "Items per page",
309
+ options=[10, 20, 50, 100],
310
+ value=20
311
+ )
312
+
313
+ total_pages = len(filtered_content) // items_per_page + (1 if len(filtered_content) % items_per_page > 0 else 0)
314
+ current_page = st.number_input(
315
+ "Page",
316
+ min_value=1,
317
+ max_value=total_pages,
318
+ value=1
319
+ )
320
+
321
+ start_idx = (current_page - 1) * items_per_page
322
+ end_idx = min(start_idx + items_per_page, len(filtered_content))
323
+
324
+ st.write(f"Showing {start_idx + 1} to {end_idx} of {len(filtered_content)} titles")
325
+
326
+ # Show items for current page
327
+ for i, content in enumerate(filtered_content[start_idx:end_idx], start=start_idx + 1):
328
+ with st.expander(f"{i}. {content.get('title', 'N/A')} ({content.get('release_year', 'N/A')})"):
329
  # Content details in columns
330
  detail_col1, detail_col2 = st.columns(2)
331
 
 
336
 
337
  with detail_col2:
338
  st.write(f"**🎬 Genre:** {content.get('listed_in', 'N/A')}")
339
+ # Fix cast handling to prevent NoneType error
340
+ cast = content.get('cast')
341
+ cast_display = cast[:100] + "..." if cast else "N/A"
342
+ st.write(f"**πŸ‘₯ Cast:** {cast_display}")
343
  st.write(f"**πŸ“ Director:** {content.get('director', 'N/A')}")
344
 
345
  # Description
346
  st.write(f"**πŸ“– Description:**")
347
  st.write(content.get('description', 'N/A'))
348
 
349
+ # Add page navigation buttons
350
+ col1, col2, col3 = st.columns([1, 2, 1])
351
+ with col1:
352
+ if current_page > 1:
353
+ if st.button("⬅️ Previous"):
354
+ st.session_state.page = current_page - 1
355
+ with col3:
356
+ if current_page < total_pages:
357
+ if st.button("Next ➑️"):
358
+ st.session_state.page = current_page + 1
359
+
360
+ # Show page info
361
+ with col2:
362
+ st.write(f"Page {current_page} of {total_pages}")
363
  else:
364
  st.info("No content matches your current filters. Try adjusting the criteria.")
365