| 415 | return ujson.dumps(postval) |
| 416 | |
| 417 | def DBFetcherLess(self, limit, date): |
| 418 | mainlist = [] |
| 419 | postval = {} |
| 420 | try: |
| 421 | postval["posts"] = None |
| 422 | if limit.isdigit() == False and date.isdigit() == False: |
| 423 | raise Exception |
| 424 | limit = int(limit) |
| 425 | date = int(date) |
| 426 | doc = ( |
| 427 | self._collection.find({"date": {"$lt": date}}) |
| 428 | .limit(limit) |
| 429 | .sort("date", pymongo.DESCENDING) |
| 430 | ) |
| 431 | for i in doc: |
| 432 | del i["_id"] |
| 433 | mainlist.append(i) |
| 434 | postval["posts"] = mainlist[::-1] |
| 435 | postval["status"] = True |
| 436 | except Exception as err: |
| 437 | print(f"error : {err}\n") |
| 438 | print("error::", sys.exc_info()[1]) |
| 439 | postval["status"] = False |
| 440 | finally: |
| 441 | return ujson.dumps(postval) |
| 442 | |
| 443 | def __del__(self): |
| 444 | self.mon.close() |