Spaces:
Running
Running
File size: 3,217 Bytes
68a2a86 bf84dca 68a2a86 bf84dca f814edc bf84dca 0d110c1 45c021b bf84dca |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
import re
import time
import pymongo
import motor.motor_asyncio
from bson.objectid import ObjectId
from bson.errors import InvalidId
from bson.json_util import dumps
from pymongo.errors import PyMongoError
class PUBLICFilesDB:
def __init__(self, uri, database_name):
self._client = motor.motor_asyncio.AsyncIOMotorClient(uri)
self.db = self._client[database_name]
self.files = self.db.Public_Files
async def GetSeriesAllBy10(self, offset=None):
try:
filter = {"type": "TVSeries"} # Define the filter for movies
total_results = await self.files.count_documents(filter)
offset=int( offset if offset else 0)
next_offset = offset + 10
if next_offset >= total_results: # Changed > to >= to handle the last page correctly
next_offset = ''
cursor = self.files.find(filter) # Apply the filter
cursor.sort('$natural', pymongo.DESCENDING) # Use pymongo.DESCENDING
cursor.skip(offset).limit(10)
files = await cursor.to_list(length=10)
return files, next_offset
except PyMongoError as e:
print(f"MongoDB error: {e}")
return [], '' # Return empty list and '' on error
except Exception as e:
print(f"An unexpected error occurred: {e}")
return [], ''
async def GetMoviesAllBy10(self, offset=None):
try:
filter = {"type": "Movie"} # Define the filter for movies
total_results = await self.files.count_documents(filter)
offset=int( offset if offset else 0)
next_offset = offset + 10
if next_offset >= total_results: # Changed > to >= to handle the last page correctly
next_offset = ''
cursor = self.files.find(filter) # Apply the filter
cursor.sort('$natural', pymongo.DESCENDING) # Use pymongo.DESCENDING
cursor.skip(offset).limit(10)
files = await cursor.to_list(length=10)
return files, next_offset
except PyMongoError as e:
print(f"MongoDB error: {e}")
return [], '' # Return empty list and '' on error
except Exception as e:
print(f"An unexpected error occurred: {e}")
return [], ''
async def GetLatestAllBy10(self, offset=None):
try:
total_results = await self.files.count_documents({})
offset=int( offset if offset else 0)
next_offset = offset + 10
if next_offset >= total_results: # Changed > to >= to handle the last page correctly
next_offset = ''
cursor = self.files.find({}) # Apply the filter
cursor.sort('$natural', pymongo.DESCENDING ) # Use pymongo.DESCENDING
cursor.skip(offset).limit(10)
files = await cursor.to_list(length=10)
return files, next_offset
except PyMongoError as e:
print(f"MongoDB error: {e}")
return [], '' # Return empty list and '' on error
except Exception as e:
print(f"An unexpected error occurred: {e}")
return [], ''
|