MCPcopy Create free account
hub / github.com/geekcomputers/Python / DBDataFetcher

Class DBDataFetcher

insta_monitering/insta_datafetcher.py:363–444  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

361
362
363class DBDataFetcher:
364 def __init__(self, user, tags, type, productId):
365 try:
366 self.mon = pymongo.MongoClient(host=config.host, port=config.mongoPort)
367 db = self.mon[productId + ":" + user + ":insta"]
368 self._collection = db[tags]
369 except Exception as err:
370 print(f"exception : {err}\n")
371 print("error::DBDataFetcher.init>>", sys.exc_info()[1])
372
373 def dbFetcher(self, limit=20):
374 mainlist = []
375 try:
376 records = self._collection.find().sort("id", -1).limit(limit)
377 for i in records:
378 del i["_id"]
379 mainlist.append(i)
380 except Exception as err:
381 print(f"exception : {err}\n")
382 print("error::dbFetcher>>", sys.exc_info()[1])
383 finally:
384 return ujson.dumps(mainlist)
385
386 def DBFetcherGreater(self, limit, date):
387 mainlist = []
388 postval = {}
389 try:
390 postval["posts"] = None
391 if limit.isdigit() == False and date.isdigit() == False:
392 raise Exception
393 limit = int(limit)
394 date = int(date)
395 if date != 0:
396 doc = (
397 self._collection.find({"date": {"$gt": date}})
398 .sort("date", pymongo.ASCENDING)
399 .limit(limit)
400 )
401 else:
402 doc = (
403 self._collection.find().sort("date", pymongo.ASCENDING).limit(limit)
404 )
405 for i in doc:
406 del i["_id"]
407 mainlist.append(i)
408 postval["posts"] = mainlist
409 postval["status"] = True
410 except Exception as err:
411 print(f"exception : {err}\n")
412 print("error::", sys.exc_info()[1])
413 postval["status"] = False
414 finally:
415 return ujson.dumps(postval)
416
417 def DBFetcherLess(self, limit, date):
418 mainlist = []
419 postval = {}
420 try:

Callers 2

getMethod · 0.85
getMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected