Beispiel #1
0
	def add_user(cls, user):
		if user is None:
			logger.error('Missing field \'user\'')
			raise tornado.gen.Return(None)
		id_ = user.get('id', str(uuid.uuid1()))
		password_ = user.get('password')
		if password_ is None or len(password_) == 0:
			logger.error('Missing field \'password\'')
			raise tornado.gen.Return(None)
		name_ = user.get('name', '')
		tel_ = user.get('tel', '')
		email_ = user.get('email', '')
		deviceid_ = user.get('deviceid', '')
		sql_statement = ('INSERT INTO `users` '
				'(`id`, `password`, `name`, `tel`, `email`, `deviceid`)'
				' VALUES '
				'(%s, %s, %s, %s, %s, %s)')
		pool = common.get_mysql_pool()
		if pool is None:
			logger.error('Unknown connection pool')
			raise tornado.gen.Return(None)
		try:
			yield pool.execute(sql_statement, (id_ , password_, name_, tel_, email_, deviceid_))
		except Exception, e:
			logger.error(e)
			raise tornado.gen.Return(None)
Beispiel #2
0
	def add_cuisinebook(self,cuisinebook):
		cuisineBookId = cuisinebook.get('cuisineBookId')
		dishName = cuisinebook.get('dishname')
		needTime = cuisinebook.get('needtime')
		difficulty = cuisinebook.get('difficulty')
		stepsNum = cuisinebook.get('stepnum')
		#stepsNum = 3
		logger.info(dishName)
		tips = cuisinebook.get('TipsSteps')
		CookStep = cuisinebook.get('FoodSteps')
		FoodMaterial = cuisinebook.get('FoodMaterial')
		
		sql_statement = ('REPLACE INTO `CuisineBook` '
				'(`cuisineBookId`, `dishName`, `needTime`, `difficulty`, `stepsNum`, `tips`, `CookStep`, `FoodMaterial`)'
				' VALUES '
				'(%s, %s, %s, %s, %s, %s, %s, %s)')
		pool = common.get_mysql_pool()
		if pool is None:
			logger.error('Unknown connection pool')
			raise tornado.gen.Return(None)
		try:
			yield pool.execute(sql_statement, (cuisineBookId , dishName, needTime, difficulty, stepsNum, tips,  CookStep, FoodMaterial))	
			raise tornado.gen.Return(cuisineBookId)
		except Exception, e:
			logger.error(e)
			raise tornado.gen.Return(None)
Beispiel #3
0
	def get_somecuisinebook_by_time(self, kBCreateTime, cuisineBookNum):
        	sql_statement = ('SELECT * from `kBCookBook` where `kBCreateTime` < %d ORDER BY kBCreateTime DESC LIMIT %d' % (kBCreateTime, cuisineBookNum))
        	pool = common.get_mysql_pool()
        	if pool is None:
            		logger.error('Unknown connection pool')
        	cur = None
        	try:
            		cur = yield pool.execute(sql_statement)
        	except Exception, e:
            		logger.error(e)
Beispiel #4
0
	def check_cuisinebook(self,cuisineBookId):
		sql_statement = ('SELECT * from `kBCookBook` WHERE `kBCookBookId` = %s')
		pool = common.get_mysql_pool()
		if pool is None:
			logger.error('Unknown connection pool')
		cur = None
		try:
			cur = yield pool.execute(sql_statement, (cuisineBookId))
		except Exception, e:
			logger.error(e)
Beispiel #5
0
	def check_product(self,productId):
		sql_statement = ('SELECT * from `Prouct` WHERE `kPProuctId` = %s')
		pool = common.get_mysql_pool()
		if pool is None:
			logger.error('Unknown connection pool')
		cur = None
		try:
			cur = yield pool.execute(sql_statement, (productId))
		except Exception, e:
			logger.error(e)
Beispiel #6
0
	def check_cuisineimage(self, imagemd5):
		sql_statement = ('SELECT `image64` from `icon` WHERE`imagemd5` = %s')
		pool = common.get_mysql_pool()
		if pool is None:
			logger.error('Unknown connection pool')
			cur = None
		try:
			cur = yield pool.execute(sql_statement, (imagemd5))
		except Exception, e:
			logger.error(e)
Beispiel #7
0
 	def get_someproduct_by_time(self, kPCreateTime, someproduct):
     	sql_statement = ('SELECT * from `Prouct` where `kPCreateTime` < %d ORDER BY kPCreateTime DESC LIMIT %d' % (kPCreateTime, someproduct))
    	 	pool = common.get_mysql_pool()
     	if pool is None:
         		logger.error('Unknown connection pool')
     	cur = None
     	try:
         		cur = yield pool.execute(sql_statement)
     	except Exception, e:
         		logger.error(e)
Beispiel #8
0
 def get_someproduct_by_cookerid(self, kPCookerId, kPoffset, someproduct):
         sql_statement = ("SELECT * from `Prouct` where `kPCookerId` = '%s' ORDER BY kPCreateTime DESC LIMIT %d,%d" % (kPCookerId, kPoffset, someproduct))
         pool = common.get_mysql_pool()
         if pool is None:
                 logger.error('Unknown connection pool')
         cur = None
         try:
                 cur = yield pool.execute(sql_statement)
         except Exception, e:
                 logger.error(e)
Beispiel #9
0
        def get_somecuisinebook_by_cookerid(self, kBCookerId, kBoffset, cuisineBookNum):
                sql_statement = ("SELECT * from `kBCookBook` where `kBCookerId` = '%s' ORDER BY kBCreateTime DESC LIMIT %d,%d" % (kBCookerId, kBoffset, cuisineBookNum))
                pool = common.get_mysql_pool()
		print 'find by cookerid'
                if pool is None:
                        logger.error('Unknown connection pool')
                cur = None
                try:
                        cur = yield pool.execute(sql_statement)
                except Exception, e:
                        logger.error(e)
Beispiel #10
0
	def fetch_profile_by_tel(cls, tel):
		if tel is None:
			logger.error('Missing argument \'tel\'')
			raise tornado.gen.Return(None)
		sql_statement = 'SELECT * FROM `users` WHERE `tel` = %s'
		pool = common.get_mysql_pool()
		if pool is None:
			logger.error('Unknown connection pool')
			raise tornado.gen.Return(None)
		cur = None
		try:
			cur = yield pool.execute(sql_statement, (tel,))
		except Exception, e:
			logger.error(e)
			raise tornado.gen.Return(None)
Beispiel #11
0
	def fetch_avatar(cls, id_):
		if id_ is None:
			logger.error('Missing argument \'id\'')
			raise tornado.gen.Return(None)
		sql_statement = 'SELECT `avatar` FROM `users` WHERE `id` = %s'
		pool = common.get_mysql_pool()
		if pool is None:
			logger.error('Unknown connection pool')
			raise tornado.gen.Return(None)
		cur = None
		try:
			cur = yield pool.execute(sql_statement, (id_,))
		except Exception, e:
			logger.error(e)
			raise tornado.gen.Return(None)
Beispiel #12
0
	def add_cuisineimage(self,cuisineimage):
		iconid = cuisineimage.get('iconid', str(uuid.uuid1()))
		imagemd5 = cuisineimage.get('imagemd5')
		print 'iconid:%s ' % iconid
		image64 = cuisineimage.get('image64')
		
		sql_statement = ('REPLACE INTO `icon` '
				'(`iconid`, `imagemd5`, `image64`)'
				' VALUES '
				'(%s, %s, %s)')
		pool = common.get_mysql_pool()
		if pool is None:
			logger.error('Unknown connection pool')
			raise tornado.gen.Return(None)
		try:
			yield pool.execute(sql_statement, (iconid, imagemd5, image64))	
		except Exception, e:
			logger.error(e)
			raise tornado.gen.Return(None)
Beispiel #13
0
	def add_cuisinebook_all(self,cuisinebook):
		kBCookBookId = cuisinebook.get('kBCookBookId', str(uuid.uuid1()))
		kBCookerId = cuisinebook.get('kBCookerId', '')
		kBDishName = cuisinebook.get('kBDishName', '')
		kBFavorNums = cuisinebook.get('kBFavorNums', 0)
		kBDescription = cuisinebook.get('kBDescription', '')
		kBTips = cuisinebook.get('kBTips', '')
		kBFoodMaterials = cuisinebook.get('kBFoodMaterials', '')
		kBIsPublish = cuisinebook.get('kBIsPublish', False)
		kBCreateTime = cuisinebook.get('kBCreateTime', '0')
		kBKind = cuisinebook.get('kBKind', '')
		kBFollowMadeNums = cuisinebook.get('kBFollowMadeNums', '')
		kBVisitNums = cuisinebook.get('kBVisitNums', '')
		kBTopic = cuisinebook.get('kBTopic', '')
		kBSubKind = cuisinebook.get('kBSubKind', '')
		kBFrontCoverUrl = cuisinebook.get('kBFrontCoverUrl', '')
		kBStepNums = cuisinebook.get('kBStepNums', '')
		kBVideoUrl = cuisinebook.get('kBVideoUrl', '')
		kBTags = cuisinebook.get('kBTags', '')
		logger.info(kBDishName)
		kBTimeNeeded = cuisinebook.get('kBTimeNeeded', '')
		kBCookSteps = cuisinebook.get('kBCookSteps', '')
		kBNickName = cuisinebook.get('kBNickName', '')
		kBIconUrl = cuisinebook.get('kBIconUrl', '')
        
		sql_statement = ('REPLACE INTO `kBCookBook` '
                '(`kBCookBookId`, `kBCookerId`, `kBDishName`, `kBFavorNums`, `kBDescription`, `kBTips`, `kBFoodMaterials`,'
                '`kBIsPublish`, `kBKind`, `kBFollowMadeNums`, `kBVisitNums`, `kBTopic`, `kBSubKind`, '
                '`kBFrontCoverUrl`, `kBStepNums`, `kBVideoUrl`, `kBTags`, `kBTimeNeeded`, `kBCookSteps`, `kBNickName`, `kBIconUrl`, `kBCreateTime`)'
                ' VALUES '
                '(%s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s, %s, %s, %s, %s,%s, %s)')
		pool = common.get_mysql_pool()
		if pool is None:
			logger.error('Unknown connection pool')
			raise tornado.gen.Return(None)
		try:
			cur = yield pool.execute(sql_statement, (kBCookBookId, kBCookerId, kBDishName, kBFavorNums, kBDescription, kBTips, kBFoodMaterials, 
                                               kBIsPublish, kBKind, kBFollowMadeNums, kBVisitNums, kBTopic, kBSubKind, 
                                               kBFrontCoverUrl, kBStepNums, kBVideoUrl, kBTags, kBTimeNeeded, kBCookSteps, kBNickName, kBIconUrl, kBCreateTime))    
		except Exception, e:
			logger.error(e)
			raise tornado.gen.Return(None)
Beispiel #14
0
	def modify_password_by_tel(cls, tel, new_password):
		if tel is None:
			logger.error('Missing argument \'tel\'')
			raise tornado.gen.Return(None)
		if new_password is None or len(new_password) == 0:
			logger.error('Missing argument \'password\'')
			raise tornado.gen.Return(None)
		sql_statement = ('UPDATE `users` SET '
				'`password` = %s'
				' WHERE '
				'`tel` = %s')
		pool = common.get_mysql_pool()
		if pool is None:
			logger.error('Unknown connection pool')
			raise tornado.gen.Return(None)
		cur = None
		try:
			cur = yield pool.execute(sql_statement, (new_password, tel))
		except Exception, e:
			logger.error(e)
			raise tornado.gen.Return(None)
Beispiel #15
0
	def modify_avatar(cls, id_, avatar_base64string):
		if id_ is None:
			logger.error('Missing argument \'id\'')
			raise tornado.gen.Return(None)
		if avatar_base64string is None or len(avatar_base64string) == 0:
			logger.error('Missing argument \'avatar_base64string\'')
			raise tornado.gen.Return(None)
		sql_statement = ('UPDATE `users` SET '
				'`avatar` = %s'
				' WHERE '
				'`id` = %s')
		pool = common.get_mysql_pool()
		if pool is None:
			logger.error('Unknown connection pool')
			raise tornado.gen.Return(None)
		cur = None
		try:
			cur = yield pool.execute(sql_statement, (avatar_base64string, id_))
		except Exception, e:
			logger.error(e)
			raise tornado.gen.Return(None)
Beispiel #16
0
	def add_product(self,product):
		kPProuctId = product.get('kPProuctId', str(uuid.uuid1()))
		kPCookerId = product.get('kPCookerId', '')
		kPDishName = product.get('kPDishName', '')
		kPFollowBookId = product.get('kPFollowBookId','')
		kPPhotoNums = product.get('kPPhotoNums', '')
		kPFrontCoverUrl = product.get('kPFrontCoverUrl', '')
		kPTopic = product.get('kPTopic', '')
		kPDescription = product.get('kPDescription', '')
		kPKind = product.get('kPKind', '')
		kPSubKind = product.get('kPSubKind', '')
		kPIsPublished = product.get('kPIsPublished', '0')
		kPTags = product.get('kPTags', '')
		kPTips = product.get('kPTips', '')
		kPCreateTime = product.get('kPCreateTime', '0')
		kPScore = product.get('kPScore', '')
		kPPhotos = product.get('kPPhotos', '')
		kPNickName = product.get('kPNickName', '')
		kPIconUrl = product.get('kPIconUrl', '')

		sql_statement = ('REPLACE INTO `Prouct` '
		'(`kPProuctId`, `kPCookerId`, `kPDishName`, `kPFollowBookId`, `kPPhotoNums`, `kPFrontCoverUrl`, `kPTopic`, `kPDescription`, '
		'`kPKind`, `kPSubKind`, `kPIsPublished`, `kPTags`, `kPTips`, '
		'`kPScore`, `kPPhotos`, `kPNickName`, `kPIconUrl`,  `kPCreateTime`)'
		' VALUES '
		'(%s, %s, %s, %s, %s,%s, %s, %s, %s,%s, %s,%s, %s, %s, %s, %s,%s, %s)')
		pool = common.get_mysql_pool()
		if pool is None:
			logger.error('Unknown connection pool')
			raise tornado.gen.Return(None)
		try:
			yield pool.execute(sql_statement, (kPProuctId, kPCookerId, kPDishName, kPFollowBookId, kPPhotoNums, kPFrontCoverUrl, kPTopic, kPDescription,
                                               kPKind, kPSubKind, kPIsPublished, kPTags, kPTips,  
                                               kPScore, kPPhotos, kPNickName, kPIconUrl, kPCreateTime))    
		except Exception, e:
			logger.error(e)
			raise tornado.gen.Return(None)
Beispiel #17
0
	def update_profile(cls, profile):# TODO Avatar
		if profile is None:
			logger.error('Missing argument \'profile\'')
			raise tornado.gen.Return(None)
		id_ = profile.get('id')
		if id_ is None:
			logger.error('Missing argument \'id\'')
			raise tornado.gen.Return(None)
		sql_statement = 'SELECT * FROM `users` WHERE `id` = %s'
		pool = common.get_mysql_pool()
		if pool is None:
			logger.error('Unknown connection pool')
			raise tornado.gen.Return(None)
		cur = yield pool.execute(sql_statement, (id_,))
		if cur.rowcount == 0:
			logger.error('User not found')
			raise tornado.gen.Return(None)
		raw_user = cur.fetchone()
		name_ = profile.get('name', raw_user.get('name'))
		tel_ = profile.get('tel', raw_user.get('tel'))
		email_ = profile.get('email', raw_user.get('email'))
		deviceid_ = profile.get('deviceid', raw_user.get('deviceid'))
		sql_statement = ('UPDATE `users` SET '
				'`name` = %s, '
				'`tel` = %s, '
				'`email` = %s, '
				'`deviceid` = %s'
				' WHERE '
				'`id` = %s')
		cur = None
		try:
			cur = yield pool.execute(sql_statement, 
				(name_, tel_, email_, deviceid_, id_))
		except Exception, e:
			logger.error(e)
			raise tornado.gen.Return(None)