本文整理汇总了Python中MySQL.MySQL类的典型用法代码示例。如果您正苦于以下问题:Python MySQL类的具体用法?Python MySQL怎么用?Python MySQL使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MySQL类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: StartTranscodeService
def StartTranscodeService():
import socket
hostname = socket.gethostname()
pid = os.getpid()
f = open('transcoder.pid', 'wb')
f.write(str(pid))
f.close()
signal.signal(signal.SIGTERM, sig_handler)
signal.signal(signal.SIGINT, sig_handler)
db = MySQL()
transcoder = Transcoder(Started = __Started, Progress = __Progress, Finished = __Finished, Error = __Error)
uploadDirectory = applicationConfig.get('Server','Upload')
videoDirectory = applicationConfig.get('Video','SavePath')
if not os.path.exists(videoDirectory):
os.makedirs(videoDirectory)
while True:
if __shutdown.wait(1):
break; # exit thread
if transcoder.Count() > 0:
continue; # wait process
taskList = db.list('SELECT * FROM `video_transcode` WHERE `transcoder` IS NULL ORDER BY `id` LIMIT 0,1 FOR UPDATE')
for task in taskList:
db.update("UPDATE `video_transcode` set `transcoder` = %s WHERE `id` = %s", (hostname, task['id']))
db2 = MySQL()
videoInstance = db2.get("SELECT * FROM `video` WHERE `id`=%s", (task['video_id']))
if videoInstance:
fileName = "%s/%s" % (uploadDirectory, videoInstance['upload_id'])
destFileName = "%s/%s" % (videoDirectory, task['file_name'])
transcoder.addTask({
'file' : fileName,
'video_codec' : task['video_codec'],
'video_bitrate' : task['video_bitrate'],
'video_width' : task['video_width'],
'video_height' : task['video_height'],
'audio_codec' : task['audio_codec'],
'audio_channels': task['audio_channels'],
'audio_bitrate' : task['audio_bitrate'],
'output' : destFileName,
}, arg = task['id'])
db.end()
while transcoder.Count() > 0:
theading.sleep(1)
print '.'
开发者ID:xaccc,项目名称:videoapiserver,代码行数:55,代码来源:Transcoder.py
示例17: share_list
def share_list(data):
"""
获取分享列表
方法:
share_list
参数:
UserKey[string] –用户登录后的会话ID。
Offset[long] – 列表起始位置。
Max[long] – 列表最大条数
返回值:
Count[long] – 列表数量(全部)
Offset[long] – 列表起始位置。
Max[long] – 列表最大条数
Results[Array] – 视频对象列表,视频对象定义如下:
to_time[date] – 创作日期
to_name[date] – 分享日期
VID[string] – 视频ID
"""
userId = UserService.user_id(data['UserKey'])
db = MySQL()
offset = data.get('Offset', 0)
listMax = min(100, data.get('Max', 10))
count = long(db.get('SELECT COUNT(*) as c FROM `share_list` WHERE (`owner_id` = %s and flag=0) or (`to_user_id` = %s and flag = 1)', (userId,userId)).get('c'))
results = []
shareListInstance = db.list('SELECT * FROM `share_list` WHERE (`owner_id` = %s and flag=0) or (`to_user_id` = %s and flag = 1) ORDER BY `to_time` DESC LIMIT %s,%s', (userId, userId, offset, listMax))
for shareInstance in shareListInstance:
results.append({
'ToTime' : shareInstance['to_time'],
'ToName' : shareInstance['to_name'],
'VID' : shareInstance['video_id'],
'Flag' : shareInstance['flag'],
})
return {
'Count' : count,
'Offset' : offset,
'Max' : listMax,
'Results' : results,
}
开发者ID:xaccc,项目名称:videoapiserver,代码行数:43,代码来源:ShareService.py
示例18: space_res_unrelation
def space_res_unrelation(data):
userId = UserService.user_id(data['UserKey'])
db = MySQL()
# TEST AUTHORIZE
if __test_auth_edit(userId, data.get('Id', '')) > 0:
result = db.delete("DELETE FROM `space_resource` WHERE `space_id`=%s AND `res_type`=%s AND `res_id`=%s",
(data.get('Id', ''), data.get('ResType', ''), data.get('ResId', '')))
db.end()
if result > 0:
return {
'Id': data.get('Id', ''),
'ResType': data.get('ResType', ''),
'ResId': data.get('ResId', ''),
}
else:
raise Exception('删除失败或资源不存在')
else:
raise Exception('没有权限或空间不存在')
开发者ID:xaccc,项目名称:videoapiserver,代码行数:19,代码来源:SpaceService.py
示例19: space_authorize
def space_authorize(data):
userId = UserService.user_id(data['UserKey'])
spaceInstance = space_get(data.get('Id', ''))
if userId == spaceInstance['user_id']:
allowEdit = min(1, max(0, int(data.get('AllowEdit', 0))))
db = MySQL()
authorizeUser = UserService.user_get(data.get('UserId', ''))
result = db.update("REPLACE INTO `space_authorize` (`space_id`, `user_id`, `allow_edit`) VALUES (%s,%s,%s)",
(data.get('Id', ''), data.get('UserId', ''), allowEdit))
db.end()
return {
'Id': spaceInstance['id'],
'Name': spaceInstance['name'],
'UserId': authorizeUser['id'],
'UserName': authorizeUser['name'],
'AllowEdit': allowEdit,
}
else:
raise Exception('没有权限或空间不存在')
开发者ID:xaccc,项目名称:videoapiserver,代码行数:19,代码来源:SpaceService.py
示例20: space_create
def space_create(data):
userId = UserService.user_id(data['UserKey'])
db = MySQL()
spaceId = Utils.UUID()
result = db.save("INSERT INTO `space` (`id`, `user_id`, `name`) VALUES (%s,%s,%s)",
(spaceId, userId, data.get('Name', '')))
db.end()
space_reindex({
'UserKey': data['UserKey'],
'Id': spaceId,
'After': data.get('After', ''),
})
return {
'Id': spaceId,
'Name': data.get('Name', '')
}
开发者ID:xaccc,项目名称:videoapiserver,代码行数:19,代码来源:SpaceService.py
注:本文中的MySQL.MySQL类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论