def update_db(initial_num): a = DB.find_one("dianping_register", {"crawby": "jack"}) if a: DB.update("dianping_register", {"crawby": "jack"}, { '$set': {'initial_num': initial_num}}) else: DB.insert('dianping_register', { "crawby": "jack", 'initial_num': initial_num}) pass
def insert(self): if self.reviewId > 0: if not DB.find_one("RatingProcessed", {"reviewId": self.reviewId}): DB.insert(collection='RatingProcessed', data=self.json()) else: return True else: if not DB.find_one("RatingProcessed", {"userId": self.userId, "restId": self.restId}): DB.insert(collection='RatingProcessed', data=self.json()) else: return True return False
def insert(self): if not DB.find_one( collection_mapPoints, { 'provider': self.provider, 'location': { 'type': "Point", 'coordinates': [self.latitude, self.longitude] }, 'signalStrength': self.signalStrength, 'signalType': self.signalType, 'time': self.time, 'dbAddDate': self.dbAddDate }): DB.insert(collection=collection_mapPoints, data=self.json())
def registration(): if request.method == 'POST': name = request.form['fullname'] dob = request.form['birthdate'] email = request.form['email'] mobile = request.form['mobile'] gender = request.form['gender'] prn = request.form['prn'] lastedu = request.form['lastedu'] marks = request.form['marks'] address = request.form['address'] current = request.form['currentyear'] password = generate_password_hash(request.form['password1']) data1 = { 'Name': name, 'DOB': dob, 'Email': email, 'Mobile': mobile, 'Gender': gender, 'Address': address } collection1 = "PersonalInfo" data2 = {'Email': email, 'Password': password} collection2 = "LoginInfo" data3 = { 'Email': email, 'PRN': prn, 'Current Year': current, lastedu: marks, 'SSC': 'N/A', 'HSC': 'N/A', 'SE': 'N/A', 'TE': 'N/A', 'BE': 'N/A', 'CGPA': 'N/A' } collection3 = "AcademicInfo" data4 = {'Email': email, 'certificates': []} collection4 = "Certifications" try: DB.insert(collection1, data1) DB.insert(collection2, data2) DB.insert(collection3, data3) DB.insert(collection4, data4) flash("Registration Successful") return render_template('Login.html', username=session.get('user')) except pymongo.errors.DuplicateKeyError: flash("Record already exist.") return redirect(url_for('registration')) return render_template('register.html', username=session.get('user'))
def insert(self): if not DB.find_one("Profile", {"polls._id": self.creator}): poll = DB.insert(collection='Poll', data=self.json()) DB.update_one(collection='Profile', filter={'_id': self.creator}, data={'$push': { 'polls': poll.inserted_id }}) return poll.inserted_id
def insert(self,userEmail,userId): event = DB.insert(collection='Events', data=self.json()) DB.update_one(collection='Profile',filter={'email':userEmail}, data = {'$push': {'events':event.inserted_id}}) profilePic = DB.find_one(collection = "Profile", query = {"email": userEmail}, projection = {"pictureDir" : 1, 'firstName':1, 'lastName':1}) DB.update_one(collection = "Events", filter ={'_id':event.inserted_id}, data = {'$push': {"invitees": {"id":userId, "email": userEmail, "status": "going", "profilePic":profilePic['pictureDir'], "name":profilePic['firstName'] + " " + profilePic['lastName']}}}) return event.inserted_id
def index(): if request.method == 'GET': query = {} data = DB.find_one(collection, query) return jsonify(data), 200 data = request.get_json() if request.method == 'POST': if data.get('uuid', None): DB.insert(collection, data) return jsonify({ 'ok': True, 'message': 'Call created successfully!' }), 200 else: return jsonify({ 'ok': False, 'message': 'Bad request parameters!' }), 400
def insert(self): if self.reviewId != "": print('执行插入了1:', self.reviewId) if not DB.find_one("Ratings", {"reviewId": self.reviewId}): print() DB.insert(collection='Ratings', data=self.json()) insert_data = self.json() print('insert_data:', insert_data) else: return True else: print('执行插入了2') if not DB.find_one("Ratings", { "userId": self.userId, "restId": self.restId }): DB.insert(collection='Ratings', data=self.json()) else: return True return False
def insertList(): logger.info('insert') try: data = dict( request.json ) obj_id = DB.insert(collection='test', data=data) except Exception as error : logger.error( error ) return jsonify({ 'method': 'get' , 'url': 'http://localhost:3000/list' })
def insert(self): try: if not DB.find_one("sinfo", {"name": self.name}): # try: id = DB.insert(collection='sinfo', data=self.json()).inserted_id return (id, 204) # except pymongo.errors.ConnectionFailure as e: # return jsonify({'ok': False, 'message': str(e)}), 500 # else: #return jsonify({'ok': True, 'message': "Name already exist for {}".format(self.name))}), 400 except: e = sys.exc_info()[0] # print(e) #return ('ok': True, 'message': "Name already exist for {}".format(self.name)}, 400 return (e, 402)
def insert(self): if not DB.find_one("users", {"name": self.name}): DB.insert(collection='users', data=self.insert_json()) else: DB.update_one("users", {"name": self.name}, self.update_json())
def insert(self): DB.insert(collection='studentactivity', data=self.json())
def insert(companyObj): companyObj['created_at'] = datetime.datetime.utcnow() if DB.count("company", {"name": companyObj['name']}) <= 0: DB.insert(collection='company', data=companyObj)
def insert(self): if not DB.find_one("Courses", {"_id": self._id}): DB.insert(collection='Courses', data=self.json())
def insert(self): if not DB.find_one("Profile", {"email": self.email}): DB.insert(collection='Profile', data=self.json())
def insert(self, payload): if not DB.find_one("Students", {"_id": payload['_id']}): DB.insert(collection='Students', data=payload)
def insert(self): DB.insert(collection=collection_routePoints, data=self.json())
def insert(postingObj): postingObj['created_at'] = datetime.datetime.utcnow() if DB.count("jobPostings", {"jobId": postingObj['jobId']}) <= 0: DB.insert(collection='jobPostings', data=postingObj)
def add_job(): """Add json to the database.""" content = request.get_json() print(content) DB.insert(collection='jobs', data=content) return ('', 204)
def insert(self, payload): DB.insert(collection='Tasks', data=payload) return payload
def insert(userObj): userObj['created_at'] = datetime.datetime.utcnow() if DB.count("users", {"email": userObj['email']}) <= 0: DB.insert(collection='users', data=userObj)
def insert(self): if not DB.find_one("posts", {"title": self.title, "text": self.text}): DB.insert(collection='posts', data=self.json())
def insert(self): if not DB.find_one("jobs", {"name": self.name}): DB.insert(collection='jobs', data=self.json())
def insert(self): if not DB.find_one("User", {"email": self.email}): DB.insert(collection='User', data=self.json())