mirror of
https://github.com/abrendan/NochuSearch.git
synced 2025-06-16 04:35:08 +02:00
normal search results pages
This commit is contained in:
parent
d2057259c8
commit
3c55cd8964
11
main.py
11
main.py
@ -30,13 +30,13 @@ def search():
|
|||||||
|
|
||||||
response = requests.get(search_url, params=params)
|
response = requests.get(search_url, params=params)
|
||||||
search_results = []
|
search_results = []
|
||||||
|
total_pages = 0
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
search_data = response.json()
|
search_data = response.json()
|
||||||
|
|
||||||
items = search_data.get('items', [])
|
items = search_data.get('items', [])
|
||||||
|
|
||||||
for item in items:
|
for item in items:
|
||||||
thumbnail = item.get('pagemap', {}).get('cse_thumbnail', [{}])[0].get('src', '/path-to-default-thumbnail.jpg')
|
thumbnail = item.get('pagemap', {}).get('cse_thumbnail', [{}])[0].get('src', '/path-to-default-thumbnail.jpg')
|
||||||
|
|
||||||
search_results.append({
|
search_results.append({
|
||||||
'title': item.get('title'),
|
'title': item.get('title'),
|
||||||
'link': item.get('link'),
|
'link': item.get('link'),
|
||||||
@ -45,8 +45,7 @@ def search():
|
|||||||
})
|
})
|
||||||
|
|
||||||
total_results = int(search_data.get('searchInformation', {}).get('totalResults', 0))
|
total_results = int(search_data.get('searchInformation', {}).get('totalResults', 0))
|
||||||
total_pages = (total_results + 9) // 10
|
total_pages = max((total_results + 9) // 10, 1) # Make sure at least one page is shown
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print(f"Error: {response.status_code}")
|
print(f"Error: {response.status_code}")
|
||||||
|
|
||||||
@ -73,9 +72,9 @@ def search_images():
|
|||||||
|
|
||||||
response = requests.get(search_url, params=params)
|
response = requests.get(search_url, params=params)
|
||||||
image_results = []
|
image_results = []
|
||||||
|
total_pages = 0
|
||||||
if response.status_code == 200:
|
if response.status_code == 200:
|
||||||
search_data = response.json()
|
search_data = response.json()
|
||||||
|
|
||||||
items = search_data.get('items', [])
|
items = search_data.get('items', [])
|
||||||
for item in items:
|
for item in items:
|
||||||
image = item.get('link', '/path-to-default-image.jpg')
|
image = item.get('link', '/path-to-default-image.jpg')
|
||||||
@ -86,7 +85,7 @@ def search_images():
|
|||||||
})
|
})
|
||||||
|
|
||||||
total_results = int(search_data.get('searchInformation', {}).get('totalResults', 0))
|
total_results = int(search_data.get('searchInformation', {}).get('totalResults', 0))
|
||||||
total_pages = (total_results + 9) // 10
|
total_pages = max((total_results + 9) // 10, 1) # Make sure at least one page is shown
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print(f"Error: {response.status_code}")
|
print(f"Error: {response.status_code}")
|
||||||
|
@ -26,6 +26,15 @@
|
|||||||
</li>
|
</li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
<div class="navigation-buttons">
|
||||||
|
{% if page > 1 %}
|
||||||
|
<button onclick="location.href='{{ url_for('search', query=query, page=page-1) }}'" class="search-button navigation-button">❮ Prev</button>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
{% if page < total_pages %}
|
||||||
|
<button onclick="location.href='{{ url_for('search', query=query, page=page+1) }}'" class="search-button navigation-button">Next ❯</button>
|
||||||
|
{% endif %}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user