本文整理匯總了Python中MySQL.MySQL.list方法的典型用法代碼示例。如果您正苦於以下問題:Python MySQL.list方法的具體用法?Python MySQL.list怎麽用?Python MySQL.list使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類MySQL.MySQL
的用法示例。
在下文中一共展示了MySQL.list方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: invite_list
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import list [as 別名]
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,
}
示例2: video_ready
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import list [as 別名]
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
示例3: space_reindex
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import list [as 別名]
def space_reindex(data):
userId = UserService.user_id(data['UserKey'])
db = MySQL()
spaceId = data.get('Id', '')
afterId = data.get('After', '')
index = []
spaceListInstance = db.list('SELECT * FROM `space` WHERE `user_id` = %s ORDER BY `index` ASC', (userId))
for space in spaceListInstance:
index.append(space['id'])
if not spaceId in index:
raise Exception('空間不存在')
index.remove(spaceId)
if afterId == 'HEAD':
index.insert(0, spaceId)
elif afterId in index:
index.insert(index.index(afterId) + 1, spaceId)
else:
index.append(spaceId)
for i,value in enumerate(index):
db.update("UPDATE `space` SET `index` = %s WHERE `id` = %s", (i, value))
db.end()
return {
'Id': spaceId,
}
示例4: space_res_list
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import list [as 別名]
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('沒有權限或空間不存在')
示例5: StartTranscodeService
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import list [as 別名]
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 '.'
示例6: space_authorized_resources
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import list [as 別名]
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('沒有可訪問的空間')
示例7: space_list
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import list [as 別名]
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,
}
示例8: share_list
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import list [as 別名]
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,
}
示例9: space_authorize_list
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import list [as 別名]
def space_authorize_list(data):
userId = UserService.user_id(data['UserKey'])
spaceInstance = space_get(data.get('Id', ''))
if userId == spaceInstance['user_id']:
db = MySQL()
results=[]
for item in db.list("SELECT DISTINCT * FROM `space_authorize` WHERE `space_id`=%s", data.get('Id', '')):
authorizeUser = UserService.user_get(item['user_id'])
results.append({
'UserId': item['user_id'],
'UserName': authorizeUser['name'],
'AllowEdit': item['allow_edit']
})
return {
'Id': data.get('Id', ''),
'Name': spaceInstance['name'],
'Results': results
}
else:
raise Exception('沒有權限或空間不存在')
示例10: space_authorized_spaces
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import list [as 別名]
def space_authorized_spaces(data):
userId = UserService.user_id(data['UserKey'])
userInstance = UserService.user_get(userId)
db = MySQL()
results=[]
for item in db.list("SELECT DISTINCT * FROM `space_authorize` WHERE `user_id`=%s", userId):
spaceInstance = space_get(item['space_id'])
if spaceInstance:
spaceOwner = UserService.user_get(spaceInstance['user_id'], notRaise=True)
results.append({
'Id': spaceInstance['id'],
'Name': spaceInstance['name'],
'Owner': spaceOwner['name'] if spaceOwner else None,
'OwnerId': spaceInstance['user_id'],
'AllowEdit': item['allow_edit']
})
return {
'Count': len(results),
'Results': results
}
示例11: list
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import list [as 別名]
def list(userId=None):
db = MySQL()
if userId:
return db.list("SELECT * FROM `user_notify` WHERE `arrived` = 0 AND `user_id` = %s AND `create_date` >= NOW() - INTERVAL 7 DAY", (userId))
else:
return db.list("SELECT * FROM `user_notify` WHERE `arrived` = 0 AND `create_date` >= NOW() - INTERVAL 7 DAY")
示例12: video_get
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import list [as 別名]
def video_get(data):
"""
獲取視頻信息
方法:
video_get
參數:
UserKey[string] –用戶登錄後的會話ID。
VID[string] – 分配的視頻ID
返回值:
VID[string] – 視頻ID
Owner[string] – 視頻所有者,默認為視頻上傳/分享者的手機號
Title[string] – 視頻標題
Author[string] – 分享者/創作者名稱
CreateTime[date] – 創作日期
Category[string] – 視頻分類
Describe[string] – 視頻描述
Tag[string] – 視頻標簽,標簽內容有半角“,”(逗號)分割
Duration[long] – 視頻長度
Definition[long] – 視頻清晰度: 0:流暢,1:標清,2:高清,3:超清
Published[string] - 發布時間
PosterURLs[array] – 視頻截圖URLs,JPG文件,1~5個。
VideoURLs[array] – 視頻播放URLs,數量參考清晰度(清晰度+1)
"""
userId = UserService.user_id(data['UserKey'])
db = MySQL()
videoInstance = db.get('SELECT * FROM `video` WHERE `id` = %s', (data['VID']))
if videoInstance:
PosterBaseURL = Config.get('Video','PosterBaseURL')
VideoBaseURL = Config.get('Video','VideoBaseURL')
VideoURLs = []
video_urls = []
VideoBaseURL = Config.get('Video','VideoBaseURL')
VideoURLs.append("%s/%s.mp4" % (VideoBaseURL,videoInstance['id']))
videoTranscodeListInstance = db.list('SELECT * FROM `video_transcode` WHERE `video_id` = %s ORDER BY `video_width` DESC', (videoInstance['id']))
for videoTranscodeInstance in videoTranscodeListInstance:
if videoTranscodeInstance['is_ready']:
VideoURLs.append("%s/%s" % (VideoBaseURL, videoTranscodeInstance['file_name']))
video_urls.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 {
'VID' : videoInstance['id'],
'Owner' : UserService.user_mobile(videoInstance['owner_id']),
'Title' : videoInstance['title'],
'Author' : videoInstance['author'],
'CreateTime': videoInstance['create_date'],
'Category' : videoInstance['category'],
'Describe' : videoInstance['describe'],
'Tag' : videoInstance['tag'],
'AddrStr' : videoInstance['lbs_addr'],
'Longitude' : videoInstance['lbs_lon'],
'Latitude' : videoInstance['lbs_lat'],
'Duration' : videoInstance['duration'],
'Published' : videoInstance['create_time'],
'Definition': MediaProbe.definition(videoInstance['video_height']),
'Poster' : "%s/%s.jpg" % (PosterBaseURL, videoInstance['id']),
'PosterURLs': ("%s/%s.jpg" % (PosterBaseURL, videoInstance['id']), ),
'VideoURLs' : VideoURLs,
'Videos' : video_urls,
}
return None
示例13: video_list
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import list [as 別名]
def video_list(data):
"""
獲取Video列表
方法:
video_list
參數:
UserKey[string] –用戶登錄後的會話ID。
Offset[long] – 列表起始位置。
Max[long] – 列表最大條數
Sort[string] – 列表最大條數
Order[string] – 列表最大條數
返回值:
Count[long] – 列表數量(全部)
Offset[long] – 列表起始位置。
Max[long] – 列表最大條數
Results[Array] – 視頻對象列表,視頻對象定義如下:
VID[string] – 視頻ID
Owner[string] – 視頻所有者,默認為視頻上傳/分享者的手機號
Title[string] – 視頻標題
Author[string] – 分享者/創作者名稱
CreateTime[date] – 創作日期
ShareTime[date] – 分享日期
Category[string] – 視頻分類
Tag[string] – 視頻標簽,標簽內容有半角,分割
AddrStr[string] - 視頻位置信息
Longitude[float] - 視頻位置 - 經度
Latitude[float] - 視頻位置 - 緯度
Duration[long] – 視頻長度
Published[string] - 發布時間
Definition[long] – 視頻清晰度: 0:流暢,1:標清,2:高清,3:超清
PosterURLs[array] – 視頻截圖URLs,JPG文件
VideoURLs[array] – 視頻播放URLs,數量參考清晰度(清晰度+1)
"""
userId = UserService.user_id(data['UserKey'])
db = MySQL()
offset = data.get('Offset', 0)
sort = data.get('Sort', 'create_time')
order = data.get('Order', 'DESC')
listMax = min(100, data.get('Max', 10))
count = long(db.get('SELECT count(*) as c FROM `video` WHERE `owner_id` = %s', userId).get('c'))
results = []
videoListInstance = db.list('SELECT * FROM `video` WHERE `owner_id` = %s ORDER BY `create_time` DESC LIMIT %s,%s', (userId, offset, listMax))
PosterBaseURL = Config.get('Video','PosterBaseURL')
VideoBaseURL = Config.get('Video','VideoBaseURL')
for videoInstance in videoListInstance:
VideoURLs = []
video_urls = []
VideoBaseURL = Config.get('Video','VideoBaseURL')
VideoURLs.append("%s/%s.mp4" % (VideoBaseURL,videoInstance['id']))
videoTranscodeListInstance = db.list('SELECT * FROM `video_transcode` WHERE `video_id` = %s ORDER BY `video_width` DESC', (videoInstance['id']))
for videoTranscodeInstance in videoTranscodeListInstance:
if videoTranscodeInstance['is_ready']:
VideoURLs.append("%s/%s" % (VideoBaseURL, videoTranscodeInstance['file_name']))
video_urls.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']),
})
results.append({
'VID' : videoInstance['id'],
'Owner' : UserService.user_mobile(videoInstance['owner_id']),
'Title' : videoInstance['title'],
'Author' : videoInstance['author'],
'CreateTime': videoInstance['create_date'],
'Category' : videoInstance['category'],
'Describe' : videoInstance['describe'],
'Tag' : videoInstance['tag'],
'AddrStr' : videoInstance['lbs_addr'],
'Longitude' : videoInstance['lbs_lon'],
'Latitude' : videoInstance['lbs_lat'],
'Duration' : videoInstance['duration'],
'Published' : videoInstance['create_time'],
'Definition': MediaProbe.definition(videoInstance['video_height']),
'Poster' : "%s/%s.jpg" % (PosterBaseURL, videoInstance['id']),
'PosterURLs': ("%s/%s.jpg" % (PosterBaseURL, videoInstance['id']), ),
'VideoURLs' : VideoURLs,
'Videos' : video_urls,
})
return {
'Count' : count,
'Offset' : offset,
'Max' : listMax,
'Results' : results,
}
示例14: ConfigParser
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import list [as 別名]
from MySQL import MySQL
print 'start to upgrade ...'
applicationConfig = ConfigParser()
applicationConfig.read('Config.ini')
uploadDirectory = applicationConfig.get('Server','Upload')
videoDirectory = applicationConfig.get('Video','SavePath')
db = MySQL()
videoList = db.list('SELECT * FROM `video`')
for video in videoList:
print "convert %s <= %s" % (video['id'], video['upload_id'])
# 視頻文件地址
srcFileName = "%s/%s.mp4" % (videoDirectory, video['upload_id'])
destFileName = "%s/%s.mp4" % (videoDirectory, video['id'])
if not os.path.exists(srcFileName):
print '[文件被刪除] vid: %s, upload_id: %s' % (video['id'], video['upload_id'])
continue # 文件被刪除
os.rename(srcFileName, destFileName)
# 截圖文件地址