Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +32 -12
src/streamlit_app.py
CHANGED
|
@@ -40,7 +40,7 @@ def get_ai_client():
|
|
| 40 |
# =============================================================================
|
| 41 |
@st.cache_data(ttl=300) # Cache for 5 minutes
|
| 42 |
def get_netflix_content():
|
| 43 |
-
"""Fetch Netflix content from NocoDB"""
|
| 44 |
api_token, _ = get_api_credentials()
|
| 45 |
|
| 46 |
if not api_token:
|
|
@@ -52,18 +52,38 @@ def get_netflix_content():
|
|
| 52 |
"accept": "application/json"
|
| 53 |
}
|
| 54 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
try:
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
except Exception as e:
|
| 69 |
st.error(f"Error connecting to database: {e}")
|
|
|
|
| 40 |
# =============================================================================
|
| 41 |
@st.cache_data(ttl=300) # Cache for 5 minutes
|
| 42 |
def get_netflix_content():
|
| 43 |
+
"""Fetch Netflix content from NocoDB with pagination"""
|
| 44 |
api_token, _ = get_api_credentials()
|
| 45 |
|
| 46 |
if not api_token:
|
|
|
|
| 52 |
"accept": "application/json"
|
| 53 |
}
|
| 54 |
|
| 55 |
+
all_content = []
|
| 56 |
+
page = 1
|
| 57 |
+
page_size = 1000 # NocoDB default page size
|
| 58 |
+
|
| 59 |
try:
|
| 60 |
+
while True:
|
| 61 |
+
offset = (page - 1) * page_size
|
| 62 |
+
response = requests.get(
|
| 63 |
+
f"{NOCODB_URL}/cleaned_netflix_titles_csv?limit={page_size}&offset={offset}",
|
| 64 |
+
headers=headers
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
if response.status_code == 200:
|
| 68 |
+
data = response.json()
|
| 69 |
+
current_page_data = data.get('list', [])
|
| 70 |
+
|
| 71 |
+
if not current_page_data: # No more data to fetch
|
| 72 |
+
break
|
| 73 |
+
|
| 74 |
+
all_content.extend(current_page_data)
|
| 75 |
+
|
| 76 |
+
# Check if this is the last page
|
| 77 |
+
page_info = data.get('pageInfo', {})
|
| 78 |
+
if page_info.get('isLastPage', True):
|
| 79 |
+
break
|
| 80 |
+
|
| 81 |
+
page += 1
|
| 82 |
+
else:
|
| 83 |
+
st.error(f"Failed to fetch data: {response.status_code}")
|
| 84 |
+
return []
|
| 85 |
+
|
| 86 |
+
return all_content
|
| 87 |
|
| 88 |
except Exception as e:
|
| 89 |
st.error(f"Error connecting to database: {e}")
|