当前位置: 首页>>代码示例>>Python>>正文


Python MySQL.MySQL类代码示例

本文整理汇总了Python中MySQL.MySQL的典型用法代码示例。如果您正苦于以下问题:Python MySQL类的具体用法?Python MySQL怎么用?Python MySQL使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MySQL类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: space_res_list

def space_res_list(data):
	userId = UserService.user_id(data['UserKey'])
	if __test_auth_view(userId, data.get('Id', '')) > 0:
		db = MySQL()

		offset = long(data.get('Offset', 0))
		sort = max(1, min(3, int(data.get('Sort', 1))))
		order = int(data.get('Order', 0))
		listMax = min(100, data.get('Max', 10))

		resCount = db.get("SELECT COUNT(*) AS c FROM `space_resource` WHERE `space_id` = %s AND `res_type`=%s", (data.get('Id', ''), data.get('ResType', '')))['c']
		resList = db.list("SELECT * FROM `space_resource` WHERE `space_id` = %s AND `res_type`=%s", 
							(data.get('Id', ''), data.get('ResType', '')), sort='order_field%s'%sort, order='DESC' if order == 0 else 'ASC', offset=offset, pagesize=listMax )
		results = []
		for res in resList:
			results.append({
					'ResId': res['res_id'],
					'OrderField1': res['order_field1'],
					'OrderField2': res['order_field2'],
					'OrderField3': res['order_field3'],
				})

		return {
			'Id': data.get('Id', ''),
			'ResType': data.get('ResType', ''),
			'Count': resCount,
			'Offset': offset,
			'Max': listMax,
			'Sort': sort,
			'Order': order,
			'Results': results
		}
	else:
		raise Exception('没有权限或空间不存在')
开发者ID:xaccc,项目名称:videoapiserver,代码行数:34,代码来源:SpaceService.py

示例2: video_poster

def video_poster(data):
	"""
	视频截图更新
	方法:
		video_poster
	参数:
		UserKey[string] –用户登录后的会话ID。
		VID[string] – 分配的视频ID
		Time[float] – 截图播放时间点
	返回值:
		VID[string] – 视频ID
		Poster[string] – 视频截图地址
	"""
	userId = UserService.user_id(data['UserKey'])
	db = MySQL()
	videoInstance = db.get('SELECT * FROM `video` WHERE `id` = %s', (data['VID']))

	if videoInstance:
		fileName = "%s/%s.mp4" % (videoDirectory, videoInstance['id'])

		PosterBaseURL = Config.get('Video','PosterBaseURL')
		PosterURL = "%s/%s.jpg" % (PosterBaseURL, videoInstance['id'])

		Transcoder.VideoPoster(fileName, ("%s/%s.jpg" % (videoDirectory, videoInstance['id'])), ss=float(data['Time']))
		return {
			'VID'       : videoInstance['id'],
			'Poster'    : PosterURL
		}

	return None
开发者ID:xaccc,项目名称:videoapiserver,代码行数:30,代码来源:VideoService.py

示例3: invite_list

def invite_list(data):
	userId = UserService.user_id(data['UserKey'])
	db = MySQL()

	inviteListInstance = db.list('SELECT * FROM `invite` WHERE `invite_date` >= NOW() - INTERVAL 60 DAY AND `is_pocket` = 0 AND `user_id` = %s AND `type` = %s', (userId, data.get('Type', None)), sort='invite_date', order='DESC')
	
	results = []
	for invite in inviteListInstance:
		dealUser = UserService.user_get(invite['deal_user_id'], notRaise = True) if invite['deal_user_id'] else None
		results.append({
				'Code': invite['id'],
				'InviteDate': invite['invite_date'],
				'ReferId': invite['refer_id'],
				'IsDeal': invite['is_deal'],
				'DealUserId': invite['deal_user_id'] if dealUser else None,
				'DealUser': dealUser['name'] if dealUser else None,
				'DealDate': invite['deal_date'] if dealUser else None,
				'IsPocket': invite['is_pocket'],
				'PocketDate': invite['pocket_date'],
			})

	return {
		'Type': data.get('Type', None),
		'Count': len(results),
		'Results': results,
	}
开发者ID:xaccc,项目名称:videoapiserver,代码行数:26,代码来源:InviteService.py

示例4: video_ready

def video_ready(data):
	"""
	视频处理状态
	方法:
		video_ready
	参数:
		UserKey[string] –用户登录后的会话ID。
		VID[string] – 视频ID
	返回值:
		VID[string] – 视频ID
		Results[Array] – 视频对象列表,视频对象定义如下:
			Definition[string] - 清晰度
			Ready[boolean] - 是否准备就绪
			URL[string] – 视频所有者,默认为视频上传/分享者的手机号
			Progress[float] – 处理进度
	"""
	result = []
	userId = UserService.user_id(data['UserKey'])
	db = MySQL()
	videoInstance = db.get('SELECT * FROM `video` WHERE `id` = %s', (data['VID']))
	if videoInstance:

		VideoBaseURL = Config.get('Video','VideoBaseURL')
		videoTranscodeListInstance = db.list('SELECT * FROM `video_transcode` WHERE `video_id` = %s ORDER BY `video_width` DESC', (data['VID']))

		for videoTranscodeInstance in videoTranscodeListInstance:
			result.append({
				'Definition': MediaProbe.definitionName(videoTranscodeInstance['video_height'], videoTranscodeInstance['video_width']),
				'Ready'     : videoTranscodeInstance['is_ready'] == 1,
				'URL'       : "%s/%s" % (VideoBaseURL, videoTranscodeInstance['file_name']),
				'Progress'  : float(videoTranscodeInstance['progress']),
			})

	return result
开发者ID:xaccc,项目名称:videoapiserver,代码行数:34,代码来源:VideoService.py

示例5: invite_pocket

def invite_pocket(data):
	userId = UserService.user_id(data['UserKey'])
	db = MySQL()
	result = db.update("UPDATE `invite` SET `is_pocket` = 1, `pocket_date` = now() WHERE `user_id` = %s AND `id` = %s AND `is_pocket` = 0", (userId, data.get('Code', None)))
	db.end()
	if result > 0:
		return {
			'Code': data.get('Code', None)
		}
	else:
		raise Exception('邀请码不存在或已处理')
开发者ID:xaccc,项目名称:videoapiserver,代码行数:11,代码来源:InviteService.py

示例6: create

def create(toUserId, notifyContent, sender=None, refId=None):
	notifyId = Utils.UUID()
	db = MySQL()
	db.save("INSERT INTO `user_notify` (`id`,`user_id`,`notify`,`sender`,`ref_id`) VALUES (%s,%s,%s,%s,%s)", (notifyId, toUserId, notifyContent, sender, refId))
	db.end()

	try:
		NotifyTCPServer.notify_server_has_new(toUserId)
	except Exception as e:
		print "Error: %s" % e

	return notifyId
开发者ID:xaccc,项目名称:videoapiserver,代码行数:12,代码来源:NotifyService.py

示例7: invite_code

def invite_code(data):
	userId = UserService.user_id(data['UserKey'])
	db = MySQL()

	code = Utils.UUID()
	result = db.save("INSERT INTO `invite` (`id`, `user_id`, `type`, `refer_id`, `info`) VALUES (%s,%s,%s,%s,%s)", 
					(code, userId, data.get('Type', None), data.get('ReferId', None), data.get('Info', None)))
	db.end()

	return {
		'Code': code,
	}
开发者ID:xaccc,项目名称:videoapiserver,代码行数:12,代码来源:InviteService.py

示例8: reverseShortUrl

def reverseShortUrl(shortUrl):
	result = None

	splitIdx = shortUrl.rindex('/')
	num = NumberCodec.decode(shortUrl[splitIdx+1:].split('?')[0]) if splitIdx >= 0 else NumberCodec.decode(shortUrl.split('?')[0])

	db = MySQL()
	# first find
	urlInstance = db.get(r"SELECT * FROM `short_urls` WHERE `id`=%s", num)
	if urlInstance:
		result = urlInstance['url']

	return result
开发者ID:xaccc,项目名称:videoapiserver,代码行数:13,代码来源:ShortUrlService.py

示例9: space_rename

def space_rename(data):
	userId = UserService.user_id(data['UserKey'])
	db = MySQL()
	result = db.update("UPDATE `space` SET `name` = %s WHERE `id` = %s AND `user_id` = %s", (data.get('Name', ''), data.get('Id', ''), userId))
	db.end()

	if result > 0:
		return {
			'Id': data.get('Id', ''),
			'Name': data.get('Name', ''),
		}
	else:
		raise Exception('更新失败或空间不存在')
开发者ID:xaccc,项目名称:videoapiserver,代码行数:13,代码来源:SpaceService.py

示例10: share_video

def share_video(data):
	"""
	分享视频
	方法:
		share_video
	参数:
		UserKey[string] –用户登录后的会话ID。
		VID[string] – 分配的视频ID
		To[Array] – 分享对象列表,分享对象如下定义:
			Mobile[string] – 分享手机号,必填
			Name[string] – 分享姓名,可选
	返回值:
		sessionId[string] – 分配的分享会话ID
		Results[Array] – 分享结果对象列表,分享结果对象如下定义:
			Mobile[string] – 分享手机号
			Signup[boolean] – 是否注册用户
	"""
	userId = UserService.user_id(data['UserKey'])
	db = MySQL()

	videoInstance = db.get('SELECT * FROM `video` WHERE `id` = %s', (data['VID']))
	if not videoInstance:
		raise Exception("视频不存在.")

	sessionId = Utils.UUID()
	results = []
	for to in data.get('To', ()):
		toUserId = UserService.getUserIdByMobile(to.get('Mobile'))
		result = db.save("""INSERT INTO `share` (`session_id`,`owner_id`,`video_id`,`to_user_id`,`to_mobile`,`to_name`) VALUES (%s,%s,%s,%s,%s,%s)"""
					, (sessionId, userId, data['VID'], toUserId, to.get('Mobile'), to.get('Name')))
		db.end()

		if toUserId:
			# create app notify
			NotifyService.create(toUserId, Utils.json_dumps({
				'Type'	: 'share_video',
				'From'	: UserService.user_mobile(userId),
				'To'	: to.get('Mobile'),
				'Date'	: datetime.now(),
				'VID'	: data['VID'],
			}), sender = 'share_video', refId = sessionId)

		if result:
			results.append({
				'Mobile': to.get('Mobile'),
				'Signup': toUserId != None
				})

	return {'SessionId': sessionId, 'Results': results}
开发者ID:xaccc,项目名称:videoapiserver,代码行数:49,代码来源:ShareService.py

示例11: __test_auth_view

def __test_auth_view(userId, spaceId):
	db = MySQL()
	authorized = 0
	
	# TEST AUTHORIZE
	spaceInstance = db.get('SELECT * FROM `space` WHERE `id` = %s', (spaceId))
	if spaceInstance:
		if userId == spaceInstance['user_id']:
			authorized = 1
		else:
			authorized = db.get('SELECT COUNT(*) AS c FROM `space_authorize` WHERE `space_id`=%s AND `user_id` = %s', (data.get('Id', ''), userId))['c']
	else:
		authorized = -1

	return authorized
开发者ID:xaccc,项目名称:videoapiserver,代码行数:15,代码来源:SpaceService.py

示例12: user_validate

def user_validate(data):
	db = MySQL()
	
	code = str(randint(10000,99999))
	valid_date = datetime.now() + timedelta(seconds=180)

	#
	# TODO: 发送短信到 data['Mobile'] , 验证码为 code, 过期时间 90秒
	#

	result = db.save("INSERT INTO `validate` (`mobile`, `code`, `device`, `valid_date`) VALUES (%s,%s,%s,%s)", 
					(data['Mobile'], code, data['Device'], valid_date.strftime('%Y-%m-%d %H:%M:%S')))
	db.end()

	return valid_date
开发者ID:xaccc,项目名称:videoapiserver,代码行数:15,代码来源:UserService.py

示例13: space_unauthorize

def space_unauthorize(data):
	userId = UserService.user_id(data['UserKey'])
	spaceInstance = space_get(data.get('Id', ''))
	if userId == spaceInstance['user_id']:
		db = MySQL()
		result = db.delete("DELETE FROM `space_authorize` WHERE `space_id`=%s AND `user_id`=%s", 
						(data.get('Id', ''), data.get('UserId', '')))
		db.end()
		if result > 0:
			return {
				'Id': data.get('Id', ''),
				'UserId': data.get('UserId', ''),
			}
		else:
			raise Exception('删除失败或授权不存在')
	else:
		raise Exception('没有权限或空间不存在')
开发者ID:xaccc,项目名称:videoapiserver,代码行数:17,代码来源:SpaceService.py

示例14: space_authorized_resources

def space_authorized_resources(data):
	spaceIds = []
	if data.get('SpaceId', None):
		spaceIds.append(data.get('SpaceId'))
	else:
		ownerId = data.get('OwnerId', None)
		for space in space_authorized_spaces(data)['Results']:
			if space['OwnerId'] == ownerId:
				spaceIds.append(space['Id'])

	if len(spaceIds) > 0:
		offset = long(data.get('Offset', 0))
		sort = max(1, min(3, int(data.get('Sort', 1))))
		order = int(data.get('Order', 0))
		listMax = min(100, data.get('Max', 10))

		prefixCountSQL = 'SELECT COUNT(*) AS c FROM `space_resource` WHERE `space_id` IN (%s)' % ', '.join(list(map(lambda x: '%s', spaceIds)))
		prefixSelectSQL = 'SELECT * FROM `space_resource` WHERE `space_id` IN (%s)' % ', '.join(list(map(lambda x: '%s', spaceIds)))

		db = MySQL()
		resCount = db.get(prefixCountSQL + " AND `res_type`=%s", tuple(spaceIds) + (data.get('ResType', None),)) ['c']
		resList = db.list(prefixSelectSQL + " AND `res_type`=%s", 
							tuple(spaceIds) + (data.get('ResType', None),), sort='order_field%s'%sort, order='DESC' if order == 0 else 'ASC', offset=offset, pagesize=listMax)
		results = []
		for res in resList:
			spaceInstance = space_get(res['space_id'])
			results.append({
					'Id': res['space_id'],
					'Name': spaceInstance['name'],
					'ResId': res['res_id'],
					'OrderField1': res['order_field1'],
					'OrderField2': res['order_field2'],
					'OrderField3': res['order_field3'],
				})

		return {
			'ResType': data.get('ResType', ''),
			'Count': resCount,
			'Offset': offset,
			'Max': listMax,
			'Sort': sort,
			'Order': order,
			'Results': results,
		}
	else:
		raise Exception('没有可访问的空间')
开发者ID:xaccc,项目名称:videoapiserver,代码行数:46,代码来源:SpaceService.py

示例15: space_list

def space_list(data):
	userId = UserService.user_id(data['UserKey'])
	db = MySQL()

	spaceListInstance = db.list('SELECT * FROM `space` WHERE `user_id` = %s ORDER BY `index` ASC', (userId))
	
	results = []
	for space in spaceListInstance:
		results.append({
				'Id': space['id'],
				'Name': space['name'],
			})

	return {
		'Count': len(results),
		'Spaces': results,
	}
开发者ID:xaccc,项目名称:videoapiserver,代码行数:17,代码来源:SpaceService.py


注:本文中的MySQL.MySQL类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。