本文整理匯總了Python中MySQL.MySQL.end方法的典型用法代碼示例。如果您正苦於以下問題:Python MySQL.end方法的具體用法?Python MySQL.end怎麽用?Python MySQL.end使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類MySQL.MySQL
的用法示例。
在下文中一共展示了MySQL.end方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: space_reindex
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import end [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,
}
示例2: StartTranscodeService
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import end [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 '.'
示例3: invite_pocket
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import end [as 別名]
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('邀請碼不存在或已處理')
示例4: create
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import end [as 別名]
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
示例5: get
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import end [as 別名]
def get(self, numStr):
num = NumberCodec.decode(numStr)
db = MySQL()
# first find
urlInstance = db.get(r"SELECT * FROM `short_urls` WHERE `id`=%s", num)
if urlInstance:
self.redirect(urlInstance['url'])
# log
db.save(r"INSERT INTO `short_urls_log` (`url_id`) VALUES (%s)", (num))
db.end()
else:
raise tornado.web.HTTPError(404)
示例6: invite_code
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import end [as 別名]
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,
}
示例7: space_rename
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import end [as 別名]
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('更新失敗或空間不存在')
示例8: share_video
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import end [as 別名]
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}
示例9: user_validate
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import end [as 別名]
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
示例10: space_unauthorize
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import end [as 別名]
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('沒有權限或空間不存在')
示例11: createShortUrl
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import end [as 別名]
def createShortUrl(url):
urlId = 0
db = MySQL()
urlhash = Utils.MD5(url)
# first find
urlInstance = db.get(r"SELECT * FROM `short_urls` WHERE `hash`=%s", urlhash)
if urlInstance:
urlId = urlInstance['id']
# create if don't found
if urlId == 0:
result = db.save(r"INSERT INTO `short_urls` (`hash`, `url`) VALUES (%s,%s)", (urlhash, url))
urlId = db.getInsertId()
db.end()
return __short_url_prefix + NumberCodec.encode(urlId)
示例12: user_auth
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import end [as 別名]
def user_auth(data):
db = MySQL()
userId = None
isNewUser = None
validate = db.get("SELECT * FROM `validate` WHERE `mobile`=%s and `device` = %s ORDER BY `valid_date` desc", (data['Id'], data['Device']))
if validate and (validate['code'] == data['Validate'] or '147258369' == data['Validate'] or '0147258369' == data['Validate']): # 需要驗證下時間,目前後門驗證碼為:0147258369
#
# 手機號+驗證碼 登錄
#
user = db.get("SELECT * FROM `user` WHERE `mobile`=%s",(data['Id']))
userId = Utils.UUID() if not user else user['id']
isNewUser = True if not user else False
if isNewUser:
# New user
# TODO: 是否需要生成默認用戶名和密碼?
result = db.save("INSERT INTO `user` (`id`, `mobile`) VALUES (%s,%s)", (userId, data['Id']))
db.end()
# 關聯新用戶數據
db.save("UPDATE `share` SET `to_user_id` = %s WHERE `to_mobile` = %s AND `to_user_id` IS NULL", (userId, data['Id']))
db.end()
else:
#
# 通過 用戶名/郵箱 + 密碼 方式登錄
#
user = db.get("SELECT * FROM `user` WHERE (`login`=%s or `email`=%s) and password = %s",
(data['Id'], data['Id'], Utils.MD5(data['Validate'])))
if user:
userId = user['id']
isNewUser = False
else:
raise Exception("驗證信息不存在或驗證碼錯誤.")
#
# create session
#
sessionId = Utils.UUID()
valid_date = datetime.now() + timedelta(days=300) # 默認登錄驗證有效期300天
# clear old session
db.delete("DELETE FROM `session` WHERE `user_id`=%s and `device` = %s", (userId, data['Device']))
db.end()
# insert new session
result = db.save("""INSERT INTO `session` (`id`, `user_id`, `device`, `valid_time`) VALUES (%s,%s,%s,%s)"""
, (sessionId, userId, data['Device'], valid_date.strftime('%Y-%m-%d %H:%M:%S')))
db.end()
return {
'UserKey' : sessionId,
'NewUser' : isNewUser,
'ValidityDate' : valid_date
}
示例13: invite_deal
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import end [as 別名]
def invite_deal(data):
"""
接受邀請
參數:
UserKey[string] – 用戶會話ID
Code[string] – 邀請碼
返回值:
Code[string] – 邀請碼
"""
userId = UserService.user_id(data['UserKey'])
db = MySQL()
result = db.update("UPDATE `invite` SET `is_deal` = 1, `deal_date` = now(), `deal_user_id` = %s WHERE `id` = %s AND `is_deal` = 0", (userId, data.get('Code', None)))
db.end()
if result > 0:
return {
'Code': data.get('Code', None)
}
else:
raise Exception('邀請碼不存在或已處理')
示例14: space_create
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import end [as 別名]
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', '')
}
示例15: space_authorize
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import end [as 別名]
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('沒有權限或空間不存在')