def main(): global tasks_to_accomplish mday = datetime.today().day # Month of Day wday = datetime.today().weekday() + 1 timeofDay = dtimetostrf(datetime.now()) tasks = db.find( 'notification', { '$and': [{ "timeofDay": timeofDay }, { "status": "1" }, { '$or': [{ "scheduleType": 'daily' }, { '$and': [{ "scheduleType": 'weekly' }, { "frequency": wday }] }, { '$and': [{ "scheduleType": 'monthly' }, { "frequency": mday }] }] }] }) for task in tasks: tasks_to_accomplish.put(task)
def find_test(): # Setup test. db.insert(COLLECTION, {"name": "test_data"}) selector = {"name": "test_data"} fail_selector = {"name": "fail_data"} # Check a normal find. if len(db.find(COLLECTION, selector)) != 1: print "find_test: Normal selection failed" return False # Check an empty find. if len(db.find(COLLECTION, fail_selector)) != 0: print "find_test: Empty selection failed" return False return True
def find_stress_test(): # Setup test. num_documents = 50 for i in range(num_documents): db.insert(COLLECTION, {"name": i}) # Check that all the documents are returned. if len(db.find(COLLECTION)) != num_documents: print "find_stress_test: All document selection failed." return False # Check that the correct number of documents are returned. limit = 7 if len(db.find(COLLECTION, limit=limit)) != limit: print "find_stress_test: Limited document selection failed." return False return True
for i in range(5): try: resp = rq.post(addToListLink.format(list_id=ECOMMERCE_LIST_ID, contact_id=contact_id), headers=get_headers, timeout=2) return resp except Exception as err: error = err time.sleep((2**i) + random.random()) raise error db.init() cursor = db.find('user', {}).sort('_id', -1) allusers = [] for user in cursor: if not 'eCommerceActivity' in list(user.keys()): allusers += [user] else: break # allusers += [user] cursor = db.find('user', {'ga_accesstoken': {'$ne': ''}}).sort('_id', -1) users = [] for user in cursor: if not 'eCommerceActivity' in user.keys(): users += [user] else: break
def find_by_id(sensor_id): return [data for data in db.find("sensor_data", {"id": sensor_id})]
def get_all(): return [result for result in db.find("sensor_data", {})]