本文整理汇总了Python中utils.dotdict.DotDict.get方法的典型用法代码示例。如果您正苦于以下问题:Python DotDict.get方法的具体用法?Python DotDict.get怎么用?Python DotDict.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类utils.dotdict.DotDict
的用法示例。
在下文中一共展示了DotDict.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from utils.dotdict import DotDict [as 别名]
# 或者: from utils.dotdict.DotDict import get [as 别名]
def post(self):
status = WXErrorCode.SUCCESS
try:
data = DotDict(json_decode(self.request.body))
tid = data.get('tid', None)
mannual_status = data.get('mannual_status', None)
terminal = self.db.get("SELECT mannual_status, defend_status, service_status FROM T_TERMINAL_INFO "
"WHERE tid = %s ", tid)
if terminal:
service_status = terminal['service_status']
if int(service_status) == 0:
status = WXErrorCode.OUTSERVICE
self.write_ret(status=status,
message=WXErrorCode.ERROR_MESSAGE[status])
return
try:
self.db.execute("UPDATE T_TERMINAL_INFO SET mannual_status = %s"
"WHERE tid = %s", mannual_status, tid)
except MySQLdb.Error as e:
logging.exception("[WEIXIN] execute update sql terminal:%s mannual_stauts failed ",
tid, e.args)
status = WXErrorCode.SERVER_BUSY
self.write_ret(status=status,
message=WXErrorCode.ERROR_MESSAGE[status])
except Exception as e:
logging.exception("[WEIXIN] update terminal:%s mannual_stauts failed", tid)
status = WXErrorCode.FAILED
self.write_ret(status=status,
message=WXErrorCode.ERROR_MESSAGE[status])
示例2: post
# 需要导入模块: from utils.dotdict import DotDict [as 别名]
# 或者: from utils.dotdict.DotDict import get [as 别名]
def post(self):
"""Insert new items."""
status = ErrorCode.SUCCESS
try:
data = DotDict(json_decode(self.request.body))
content = data.get('content', '')
mobiles = data.get('mobiles', None)
logging.info("[UWEB] Announcement request: %s", data)
except Exception as e:
status = ErrorCode.ILLEGAL_DATA_FORMAT
self.write_ret(status)
return
try:
mobiles_ = u''
if mobiles is not None:
mobiles_ = ','.join(mobiles)
for mobile in mobiles:
SMSHelper.send(mobile, content)
announcement = dict(cid=self.current_user.cid,
content=content,
mobiles=mobiles_)
record_announcement(self.db, announcement)
self.write_ret(status)
except Exception as e:
status = ErrorCode.SERVER_BUSY
logging.exception(
"[UWEB] record share failed, Exception: %s", e.args)
self.write_ret(status)
示例3: post
# 需要导入模块: from utils.dotdict import DotDict [as 别名]
# 或者: from utils.dotdict.DotDict import get [as 别名]
def post(self):
"""Turn on buletooth."""
status = ErrorCode.SUCCESS
try:
data = DotDict(json_decode(self.request.body))
tid = data.get('tid', None)
tids = data.get('tids', None)
self.check_tid(tid)
logging.info("[BLUETOOTH] kqly request: %s, uid: %s, tids: %s",
data, self.current_user.uid, tids)
except Exception as e:
status = ErrorCode.ILLEGAL_DATA_FORMAT
logging.exception("[UWEB] Invalid data format. body:%s, Exception: %s",
self.request.body, e.args)
self.write_ret(status)
return
try:
tids = str_to_list(tids)
tids = tids if tids else [self.current_user.tid, ]
tids = [str(t) for t in tids]
kqly(self.db, self.redis, tids)
self.write_ret(status)
except Exception as e:
logging.exception("[BLUETOOTH] Kqly failed. uid: %s, tid: %s, Exception: %s. ",
self.current_user.uid, self.current_user.tid, e.args)
status = ErrorCode.SERVER_BUSY
self.write_ret(status)
示例4: post
# 需要导入模块: from utils.dotdict import DotDict [as 别名]
# 或者: from utils.dotdict.DotDict import get [as 别名]
def post(self):
status = ErrorCode.SUCCESS
try:
data = DotDict(json_decode(self.request.body))
tid = data.get('tid', None)
tids = data.get('tids', None)
# check tid whether exist in request and update current_user
self.check_tid(tid)
logging.info("[UWEB] Defend request: %s, uid: %s, tid: %s, tids: %s",
data, self.current_user.uid, self.current_user.tid, tids)
except Exception as e:
status = ErrorCode.ILLEGAL_DATA_FORMAT
logging.exception("[UWEB] Invalid data format. body:%s, Exception: %s",
self.request.body, e.args)
self.write_ret(status)
return
try:
res = []
tids = str_to_list(tids)
tids = tids if tids else [self.current_user.tid, ]
tids = [str(tid) for tid in tids]
for tid in tids:
r = DotDict(tid=tid,
status=ErrorCode.SUCCESS)
try:
terminal = QueryHelper.get_available_terminal(tid, self.db)
if not terminal:
r.status = ErrorCode.LOGIN_AGAIN
res.append(r)
logging.error("[UWEB] The terminal with tid: %s does not exist, redirect to login.html",
tid)
continue
update_mannual_status(self.db, self.redis, tid, data.mannual_status)
logging.info("[UWEB] uid:%s, tid:%s set mannual status to %s successfully",
self.current_user.uid, tid, data.mannual_status)
except Exception as e:
r.status = ErrorCode.FAILED
logging.exception("[UWEB] uid:%s, tid:%s set mannual status to %s failed. Exception: %s",
self.current_user.uid, tid,
data.mannual_status, e.args)
finally:
res.append(r)
# NOTE: wspush
if status == ErrorCode.SUCCESS:
for tid in tids:
WSPushHelper.pushS7(tid, self.db, self.redis)
self.write_ret(status, dict_=DotDict(res=res))
except Exception as e:
logging.exception("[UWEB] uid:%s, tid:%s set mannual status to %s failed. Exception: %s",
self.current_user.uid, self.current_user.tid, data.mannual_status, e.args)
status = ErrorCode.SERVER_BUSY
self.write_ret(status)
示例5: get_tinyurl
# 需要导入模块: from utils.dotdict import DotDict [as 别名]
# 或者: from utils.dotdict.DotDict import get [as 别名]
def get_tinyurl(url):
"""Get a tiny url for wap url.
"""
try:
# Baidu dwz
#h = httplib2.Http()
#msg={'url':url}
#url_create = 'http://dwz.cn/create.php'
#response, content = h.request(url_create, "POST", urlencode(msg), headers={'Content-Type': 'application/x-www-form-urlencoded'})
#res = DotDict(json_decode(content))
#logging.info("[TINY_URL] response: %s", res)
#if res.status == 0:
# return res.tinyurl
#else:
# return None
# google
h = httplib2.Http()
url_create = 'https://www.googleapis.com/urlshortener/v1/url'
msg = json_encode({'longUrl': url})
response, content = h.request(url_create,
"POST",
msg,
headers = {'Content-Type': 'application/json'})
res = DotDict(json_decode(content))
logging.info("[TINY_URL] response: %s", res)
return res.get('id', None)
except Exception as e:
logging.exception("Get tiny url failed. Exception: %s", e.args)
return None
示例6: put
# 需要导入模块: from utils.dotdict import DotDict [as 别名]
# 或者: from utils.dotdict.DotDict import get [as 别名]
def put(self):
"""Update the parameters of terminal.
"""
status = ErrorCode.SUCCESS
try:
data = DotDict(json_decode(self.request.body))
tid = data.get('tid', None)
# check tid whether exist in request and update current_user
self.check_tid(tid)
logging.info("[UWEB] Terminal request: %s, uid: %s, tid: %s",
data, self.current_user.uid, self.current_user.tid)
except Exception as e:
status = ErrorCode.ILLEGAL_DATA_FORMAT
self.write_ret(status)
return
try:
terminal = QueryHelper.get_available_terminal(
self.current_user.tid, self.db)
if not terminal:
status = ErrorCode.LOGIN_AGAIN
logging.error("[UWEB] The terminal with tid: %s does not exist,"
" redirect to login.html",
self.current_user.tid)
self.write_ret(status)
return
user = QueryHelper.get_user_by_uid(self.current_user.uid, self.db)
if not user:
status = ErrorCode.LOGIN_AGAIN
logging.error("[UWEB] The user with uid: %s does not exist,"
" redirect to login.html",
self.current_user.uid)
self.write_ret(status)
return
# sql injection
if data.has_key('corp_cnum') and not check_cnum(data.corp_cnum):
status = ErrorCode.ILLEGAL_CNUM
self.write_ret(status)
return
# NOTE: deprecated
if data.has_key('white_list'):
white_list = ":".join(data.white_list)
if not check_sql_injection(white_list):
status = ErrorCode.ILLEGAL_WHITELIST
self.write_ret(status)
return
self.update_terminal_db(data)
# NOTE: wspush to client
if status == ErrorCode.SUCCESS:
WSPushHelper.pushS7(tid, self.db, self.redis)
self.write_ret(status)
except Exception as e:
logging.exception("[UWEB] uid:%s, tid:%s update terminal info failed. Exception: %s",
self.current_user.uid, self.current_user.tid, e.args)
status = ErrorCode.SERVER_BUSY
self.write_ret(status)
示例7: post
# 需要导入模块: from utils.dotdict import DotDict [as 别名]
# 或者: from utils.dotdict.DotDict import get [as 别名]
def post(self):
"""Clear the cookie and set defend."""
try:
data = DotDict(json_decode(self.request.body))
devid = data.get("devid", "")
logging.info("[UWEB] logout request: %s, uid: %s",
data, self.current_user.uid)
except:
self.write_ret(ErrorCode.ILLEGAL_DATA_FORMAT)
logging.error("[UWEB] illegal format, body:%s", self.request.body)
else:
# 1: if there are tids, set defend
for tid in data.tids:
update_mannual_status(self.db, self.redis, tid, UWEB.DEFEND_STATUS.YES)
# 2: remove devid from android_push_list
android_push_list_key = get_android_push_list_key(
self.current_user.uid)
android_push_list = self.redis.getvalue(android_push_list_key)
android_push_list = android_push_list if android_push_list else []
if devid in android_push_list:
android_push_list.remove(devid)
self.redis.set(android_push_list_key, android_push_list)
logging.info("[UWEB] uid:%s, android_push_lst: %s",
self.current_user.uid, android_push_list)
finally:
# 3: clear cookie
self.clear_cookie(self.app_name)
self.write_ret(ErrorCode.SUCCESS)
示例8: post
# 需要导入模块: from utils.dotdict import DotDict [as 别名]
# 或者: from utils.dotdict.DotDict import get [as 别名]
def post(self):
status = ErrorCode.SUCCESS
try:
data = DotDict(json_decode(self.request.body))
tid = data.get("tid", None)
self.check_tid(tid)
logging.info("[UWEB] terminal request: %s, uid: %s, tid: %s",
data, self.current_user.uid, self.current_user.tid)
except Exception as e:
status = ErrorCode.ILLEGAL_DATA_FORMAT
self.write(status)
return
try:
tid = data["tid"]
items = self.db.query("SELECT * FROM T_ALERT_SETTING WHERE tid=%s", tid)
if len(items) >= 7:
status = ErrorCode.FAILED
self.write_ret(status)
logging.error("[UWEB] terminal %s set too many event periods", tid)
else:
start_time = data["start_time"]
end_time = data["end_time"]
week = data["week"]
self.db.execute("INSERT INTO T_ALERT_SETTING"
" VALUES(NULL, %s, %s, %s, %s)",
tid, start_time, end_time, week)
logging.info("[UWEB] terminal add event period success: %s", data)
self.write_ret(status)
except Exception as e:
logging.exception("[UWEB] tid:%s insert event period. Exception:%s",
tid, e.args)
status = ErrorCode.FAILED
self.write_ret(status)
示例9: put
# 需要导入模块: from utils.dotdict import DotDict [as 别名]
# 或者: from utils.dotdict.DotDict import get [as 别名]
def put(self):
"""Modify some settings about mileage notification.
"""
status = ErrorCode.SUCCESS
try:
data = DotDict(json_decode(self.request.body))
logging.info("[UWEB] Mileage notification request: %s, uid: %s, tid: %s",
data, self.current_user.uid, self.current_user.tid)
tid = data.tid
except Exception as e:
status = ErrorCode.ILLEGAL_DATA_FORMAT
self.write_ret(status)
return
try:
distance_notification = data.get('distance_notification', None)
day_notification = data.get('day_notification', None)
assist_mobile = data.get('assist_mobile', None)
if distance_notification is not None:
self.db.execute("UPDATE T_MILEAGE_NOTIFICATION"
" SET distance_notification = %s,"
" notify_count = 0,"
" left_days = 1,"
" set_time = %s"
" WHERE tid = %s",
distance_notification,
int(time.time()), tid)
if day_notification is not None:
self.db.execute("UPDATE T_DAY_NOTIFICATION"
" SET day_notification = %s,"
" notify_count = 0,"
" left_days = 1,"
" set_time = %s"
" WHERE tid = %s",
day_notification,
int(time.time()), tid)
if assist_mobile is not None:
self.db.execute("UPDATE T_TERMINAL_INFO"
" SET assist_mobile = %s"
" WHERE tid = %s",
assist_mobile, tid)
self.write_ret(status)
except Exception as e:
logging.exception("[UWEB] Get mileage notification. Exception: %s",
self.current_user.cid, self.current_user.oid, e.args)
status = ErrorCode.SERVER_BUSY
self.write_ret(status)
示例10: put
# 需要导入模块: from utils.dotdict import DotDict [as 别名]
# 或者: from utils.dotdict.DotDict import get [as 别名]
def put(self):
"""Modify profile of current user.
"""
status = ErrorCode.SUCCESS
try:
data = DotDict(json_decode(self.request.body))
tid = data.get('tid',None)
# check tid whether exist in request and update current_user
self.check_tid(tid)
logging.info("[UWEB] User profile request: %s, uid: %s, tid: %s",
data, self.current_user.uid, self.current_user.tid)
except Exception as e:
status = ErrorCode.ILLEGAL_DATA_FORMAT
self.write_ret(status)
return
try:
if data.has_key('name') and not check_name(data.name):
status = ErrorCode.ILLEGAL_NAME
self.write_ret(status)
return
name = data.get('name', None)
if name is not None:
sql_cmd = "UPDATE T_USER SET name = %s WHERE uid = %s"
self.db.execute(sql_cmd,
name, self.current_user.uid)
cnum = data.get('cnum', None)
if cnum is not None:
self.db.execute("UPDATE T_CAR"
" SET cnum = %s"
" WHERE tid = %s",
safe_unicode(cnum), self.current_user.tid)
terminal_info_key = get_terminal_info_key(self.current_user.tid)
terminal_info = self.redis.getvalue(terminal_info_key)
if terminal_info:
terminal_info['alias'] = cnum if cnum else self.current_user.sim
self.redis.setvalue(terminal_info_key, terminal_info)
self.write_ret(status)
except Exception as e:
logging.exception("[UWEB] Update profile failed. uid:%s, tid:%s, Exception: %s",
self.current_user.uid, self.current_user.tid, e.args)
status = ErrorCode.SERVER_BUSY
self.write_ret(status)
示例11: post
# 需要导入模块: from utils.dotdict import DotDict [as 别名]
# 或者: from utils.dotdict.DotDict import get [as 别名]
def post(self):
"""Get a GPS location or cellid location.
workflow:
if gps:
try to get a gps location
elif cellid:
get a latest cellid and get a cellid location
"""
status = ErrorCode.SUCCESS
try:
data = DotDict(json_decode(self.request.body))
tid = data.get('tid',None)
# check tid whether exist in request and update current_user
self.check_tid(tid, finish=True)
logging.info("[UWEB] realtime request: %s, uid: %s, tid: %s",
data, self.current_user.uid, self.current_user.tid)
except Exception as e:
status = ErrorCode.ILLEGAL_DATA_FORMAT
logging.exception("[UWEB] Realtime failed. Exception: %s",
e.args)
self.write_ret(status)
self.finish()
return
current_query = DotDict()
current_query.timestamp = int(time())
terminal = QueryHelper.get_available_terminal(self.current_user.tid, self.db)
if not terminal:
status = ErrorCode.LOGIN_AGAIN
logging.error("[UWEB] The terminal with tid: %s does not exist, redirect to login.html",
self.current_user.tid)
self.write_ret(status)
self.finish()
return
current_query.locate_flag = data.locate_flag
def _on_finish(realtime):
realtime['cellid_status'] = 1
self.set_header(*self.JSON_HEADER)
self.write(json_encode(realtime))
self.finish()
def __callback(db):
self.db = db
self.request_realtime(current_query,
callback=_on_finish)
#NOTE: deprecated.
self.keep_waking(self.current_user.sim, self.current_user.tid)
self.queue.put((10, __callback))
示例12: post
# 需要导入模块: from utils.dotdict import DotDict [as 别名]
# 或者: from utils.dotdict.DotDict import get [as 别名]
def post(self):
"""Insert new items."""
status = ErrorCode.SUCCESS
try:
data = DotDict(json_decode(self.request.body))
umobile = data.umobile
umobile = data.platform
tmobile = data.get('tmobile','')
tid = data.get('tid','')
platform = data.get('platform','')
logging.info("[UWEB] share log request: %s", data)
except Exception as e:
status = ErrorCode.ILLEGAL_DATA_FORMAT
self.write_ret(status)
return
try:
record_share(self.db, locals())
self.write_ret(status)
except Exception as e:
status = ErrorCode.SERVER_BUSY
logging.exception("[UWEB] Record share failed, Exception: %s", e.args)
self.write_ret(status)
示例13: post
# 需要导入模块: from utils.dotdict import DotDict [as 别名]
# 或者: from utils.dotdict.DotDict import get [as 别名]
def post(self):
status = ErrorCode.SUCCESS
try:
data = DotDict(json_decode(self.request.body))
mobile = data.get('mobile', None)
avatar = base64.urlsafe_b64decode(str(data.avatar))
logging.info("[avatar] Request: %s, avatar: %s",
mobile, avatar)
except Exception as e:
logging.error("[avatar] Illegal format, body: %s, avatar: %s.",
self.request.body, avatar)
status = ErrorCode.ILLEGAL_DATA_FORMAT
self.write_ret(status)
return
try:
terminal = self.db.get("SELECT tid FROM T_TERMINAL_INFO WHERE mobile = %s",
mobile)
tid = terminal.tid
avatar_name = tid + '.png'
avatar_path = self.application.settings['avatar_path'] + avatar_name
avatar_full_path = self.application.settings['server_path'] + avatar_path
img = open(avatar_full_path, 'w')
img.write(avatar)
img.close()
avatar_time = self.update_avatar_time(tid)
logging.info("[avatar] avatar_time: %s, tid: %s, user: %s",
avatar_time, tid, self.current_user.uid)
if status == 0:
self.write_ret(status,
dict_=dict(avatar_path=avatar_path,
avatar_time=avatar_time))
else:
self.write_ret(status, message=ErrorCode.ERROR_MESSAGE[status],
dict_=dict(avatar_path=avatar_path,
avatar_time=avatar_time))
except Exception as e:
logging.exception("[avatar] Post avatar failed, user: %s. Exception: %s",
self.current_user.uid, e.args)
status = ErrorCode.SERVER_BUSY
self.write_ret(status)
示例14: post
# 需要导入模块: from utils.dotdict import DotDict [as 别名]
# 或者: from utils.dotdict.DotDict import get [as 别名]
def post(self):
"""Query single-events through start_time, end_time and tid.
"""
status = ErrorCode.SUCCESS
try:
data = DotDict(json_decode(self.request.body))
start_time = data.start_time
end_time = data.end_time
tid = data.tid
# For paging
page_size = int(data.get("pagesize", UWEB.LIMIT.PAGE_SIZE))
page_number = int(data.pagenum)
pagecnt = int(data.pagecnt)
logging.info("[UWEB] Single list request: %s, cid: %s", data, self.current_user.cid)
except Exception as e:
status = ErrorCode.ILLEGAL_DATA_FORMAT
logging.exception("[UWEB] Invalid data format. Exception: %s", e.args)
self.write_ret(status)
return
try:
# NOTE: we need return the event count to GUI at first time query
if pagecnt == -1:
res = QueryHelper.get_single_event(tid, start_time, end_time, self.db)
count = res.count
d, m = divmod(count, page_size)
pagecnt = (d + 1) if m else d
res = QueryHelper.get_single_event_paged(
tid, start_time, end_time, page_number * page_size, page_size, self.db
)
self.write_ret(status, dict_=DotDict(res=res, pagecnt=pagecnt))
except Exception as e:
logging.exception("[UWEB] cid: %s single list failed. Exception: %s", self.current_user.cid, e.args)
status = ErrorCode.SERVER_BUSY
self.write_ret(status)
示例15: post
# 需要导入模块: from utils.dotdict import DotDict [as 别名]
# 或者: from utils.dotdict.DotDict import get [as 别名]
def post(self):
"""Insert new items."""
status = ErrorCode.SUCCESS
try:
data = DotDict(json_decode(self.request.body))
mobile = data.get('mobile', '')
logging.info("[UWEB] feedback request: %s", data)
except Exception as e:
status = ErrorCode.ILLEGAL_DATA_FORMAT
self.write_ret(status)
return
try:
#if data.has_key('contact') and not check_sql_injection(data.contact):
# status = ErrorCode.ILLEGAL_NAME
# logging.info("[UWEB] feedback failed, Message: %s", ErrorCode.ERROR_MESSAGE[status])
# self.write_ret(status)
# return
#if data.has_key('email') and not check_sql_injection(data.email):
# status = ErrorCode.ILLEGAL_EMAIL
# logging.info("[UWEB] feedback failed, Message: %s", ErrorCode.ERROR_MESSAGE[status])
# self.write_ret(status)
# return
self.db.execute("INSERT INTO T_FEEDBACK(contact, mobile,"
" email, content, timestamp, category)"
" VALUES(%s, %s, %s, %s, %s, %s)",
data.contact, mobile, data.email,
safe_unicode(data.content),
int(time.time()), data.category)
self.write_ret(status)
except Exception as e:
status = ErrorCode.FEEDBACK_FAILED
logging.exception("[UWEB] add feedback failed, Exception: %s, content:\n%s",
e.args, data.content)
self.write_ret(status)