35 lines
1.1 KiB
Python
35 lines
1.1 KiB
Python
import os
|
|
|
|
|
|
def get_pictures_info(directory, page, page_size):
|
|
pictures = []
|
|
start_index = (page - 1) * page_size
|
|
end_index = start_index + page_size
|
|
counter = 0
|
|
|
|
for filename in os.listdir(directory):
|
|
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp')):
|
|
if start_index <= counter < end_index:
|
|
file_path = os.path.join(directory, filename)
|
|
size = os.path.getsize(file_path)
|
|
size_mb = size / (1024 * 1024)
|
|
picture_info = {
|
|
"id": counter + 1,
|
|
"photo_name": filename,
|
|
"photo_size": round(size_mb, 2),
|
|
"photo_url": file_path
|
|
}
|
|
pictures.append(picture_info)
|
|
counter += 1
|
|
if counter >= end_index:
|
|
break
|
|
return pictures
|
|
|
|
|
|
def get_total_pages(directory, page_size):
|
|
total_photos = 0
|
|
for filename in os.listdir(directory):
|
|
if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.bmp')):
|
|
total_photos += 1
|
|
return (total_photos + page_size - 1) // page_size
|