本文整理匯總了Python中MySQL.MySQL.save方法的典型用法代碼示例。如果您正苦於以下問題:Python MySQL.save方法的具體用法?Python MySQL.save怎麽用?Python MySQL.save使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類MySQL.MySQL
的用法示例。
在下文中一共展示了MySQL.save方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: user_auth
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import save [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
}
示例2: create
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import save [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
示例3: get
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import save [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)
示例4: invite_code
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import save [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,
}
示例5: share_video
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import save [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}
示例6: user_validate
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import save [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
示例7: createShortUrl
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import save [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)
示例8: space_create
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import save [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', '')
}
示例9: video_create
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import save [as 別名]
def video_create(data):
"""
設置視頻信息
方法:
video_create
參數:
UserKey[string] –用戶登錄後的會話ID。
UploadId[string] – 分配的上傳會話ID
Title[string] – 視頻標題
Author[string] – 分享者/創作者名稱
CreateTime[date] – 創作日期
Category[string] – 視頻分類
Describe[string] – 視頻描述
Tag[string] – 視頻標簽,標簽內容有半角“,”(逗號)分割
AddrStr[string] - 視頻位置信息
Longitude[float] - 視頻位置 - 經度
Latitude[float] - 視頻位置 - 緯度
返回值:
VID[string] – 視頻ID
"""
userId = UserService.user_id(data['UserKey'])
fileName = "%s/%s" % (uploadDirectory, data['UploadId'])
db = MySQL()
newId = Utils.UUID()
media = MediaProbe(fileName)
# media.createTime()
result = db.save("""INSERT INTO `video` (`id`, `upload_id`, `owner_id`, `duration`, `video_width`, `video_height`, `video_bitrate`, `title`, `author`, `create_date`, `category`, `describe`, `tag`, `lbs_addr`, `lbs_lon`, `lbs_lat`)
VALUES (%s,%s,%s,%s,%s, %s,%s,%s,%s,%s, %s,%s,%s,%s,%s,%s)""",
(newId, data['UploadId'], userId, media.duration(), media.videoWidth(), media.videoHeight(), media.videoBitrate(),
data.get('Title', ''),
data.get('Author', ''),
data.get('CreateTime', media.createTime()),
data.get('Category', ''),
data.get('Describe', ''),
data.get('Tag', ''),
data.get('AddrStr', None),
data.get('Longitude', None),
data.get('Latitude', None)))
db.end()
# 截圖
destFileName = "%s/%s.jpg" % (videoDirectory, newId)
Transcoder.VideoPoster(fileName, destFileName)
# post transcode task
# 原清晰度
if media.videoCodec() == 'h264' and media.audioCodec() == 'aac' :
result = db.save("""INSERT INTO `video_transcode` (`video_id`, `file_name`, `video_width`, `video_height`, `video_bitrate`, `video_codec`, `audio_channels`, `audio_bitrate`, `audio_codec`)
VALUES (%s,%s,%s,%s,%s, %s,%s,%s,%s)""",
(newId, newId + '.mp4',
media.videoWidth(),
media.videoHeight(),
media.videoBitrate(),
'copy',
media.audioChannels(),
media.audioBitrate(),
'copy'))
taskId = db.getInsertId()
db.end()
else:
result = db.save("""INSERT INTO `video_transcode` (`video_id`, `file_name`, `video_width`, `video_height`, `video_bitrate`, `video_codec`, `audio_channels`, `audio_bitrate`, `audio_codec`)
VALUES (%s,%s,%s,%s,%s, %s,%s,%s,%s)""",
(newId, newId + '.mp4',
media.videoWidth(),
media.videoHeight(),
media.videoBitrate(),
TranscodeTemplates.HD['video_codec'],
media.audioChannels(),
media.audioBitrate(),
TranscodeTemplates.HD['audio_codec'] ))
taskId = db.getInsertId()
db.end()
# 高清
if media.supportHD() and not media.DefinitionIsHD():
result = db.save("""INSERT INTO `video_transcode` (`video_id`, `file_name`, `video_width`, `video_height`, `video_bitrate`, `video_codec`, `audio_channels`, `audio_bitrate`, `audio_codec`)
VALUES (%s,%s,%s,%s,%s, %s,%s,%s,%s)""",
(newId, newId + '_hd.mp4',
int(TranscodeTemplates.HD['video_width']),
int(TranscodeTemplates.HD['video_width']) / media.videoAspect(),
TranscodeTemplates.HD['video_bitrate'],
TranscodeTemplates.HD['video_codec'],
TranscodeTemplates.HD['audio_channel'],
TranscodeTemplates.HD['audio_bitrate'],
TranscodeTemplates.HD['audio_codec'] ))
taskId = db.getInsertId()
db.end()
# 標清
if media.supportSD() and not media.DefinitionIsSD():
result = db.save("""INSERT INTO `video_transcode` (`video_id`, `file_name`, `video_width`, `video_height`, `video_bitrate`, `video_codec`, `audio_channels`, `audio_bitrate`, `audio_codec`)
VALUES (%s,%s,%s,%s,%s, %s,%s,%s,%s)""",
(newId, newId + '_sd.mp4',
int(TranscodeTemplates.SD['video_width']),
int(TranscodeTemplates.SD['video_width']) / media.videoAspect(),
TranscodeTemplates.SD['video_bitrate'],
#.........這裏部分代碼省略.........
示例10: MediaProbe
# 需要導入模塊: from MySQL import MySQL [as 別名]
# 或者: from MySQL.MySQL import save [as 別名]
# 短地址庫
# 創建轉碼任務
uploadFileName = "%s/%s" % (uploadDirectory, video['upload_id'])
shutil.copyfile(destFileName, uploadFileName)
newId = video['id']
media = MediaProbe(uploadFileName)
# 原清晰度
if media.videoCodec() == 'h264' and media.audioCodec() == 'aac' :
result = db.save("""INSERT INTO `video_transcode` (`video_id`, `file_name`, `video_width`, `video_height`, `video_bitrate`, `video_codec`, `audio_channels`, `audio_bitrate`, `audio_codec`)
VALUES (%s,%s,%s,%s,%s, %s,%s,%s,%s)""",
(newId, newId + '.mp4',
media.videoWidth(),
media.videoHeight(),
media.videoBitrate(),
'copy',
media.audioChannels(),
media.audioBitrate(),
'copy'))
taskId = db.getInsertId()
db.end()
else:
result = db.save("""INSERT INTO `video_transcode` (`video_id`, `file_name`, `video_width`, `video_height`, `video_bitrate`, `video_codec`, `audio_channels`, `audio_bitrate`, `audio_codec`)
VALUES (%s,%s,%s,%s,%s, %s,%s,%s,%s)""",
(newId, newId + '.mp4',
media.videoWidth(),
media.videoHeight(),
media.videoBitrate(),
TranscodeTemplates.HD['video_codec'],
media.audioChannels(),