本文整理汇总了Python中helpers.queryhelper.QueryHelper.get_white_list_by_tid方法的典型用法代码示例。如果您正苦于以下问题:Python QueryHelper.get_white_list_by_tid方法的具体用法?Python QueryHelper.get_white_list_by_tid怎么用?Python QueryHelper.get_white_list_by_tid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helpers.queryhelper.QueryHelper
的用法示例。
在下文中一共展示了QueryHelper.get_white_list_by_tid方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_white_list_by_tid [as 别名]
def get(self):
"""Get terminal info.
"""
status = ErrorCode.SUCCESS
try:
tid = self.get_argument('tid', None)
# check tid whether exist in request and update current_user
self.check_tid(tid)
car_sets = DotDict()
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_mobile(terminal.owner_mobile, self.db)
if not user:
logging.error("[UWEB] The user with uid: %s does not exist,"
" redirect to login.html",
self.current_user.uid)
self.clear_cookie(self.app_name)
self.write_ret(ErrorCode.LOGIN_AGAIN)
return
# NOTE: deprecated.
if terminal['mannual_status'] == 1:
terminal['parking_defend'] = 0
else:
terminal['parking_defend'] = 1
# NOTE: deprecated.
whitelist = QueryHelper.get_white_list_by_tid(
self.current_user.tid, self.db)
car_info = QueryHelper.get_car_by_tid(
self.current_user.tid, self.db)
car = dict(corp_cnum=car_info.get('cnum', ''))
# add tow dict: terminal, car. add two value: whitelist_1,
# whitelist_2
white_list = [terminal.owner_mobile]
for item in whitelist:
white_list.append(item['mobile'])
car_sets.update(terminal)
car_sets.update(car)
car_sets.update(DotDict(white_list=white_list))
self.write_ret(status,
dict_=dict(car_sets=car_sets))
except Exception as e:
status = ErrorCode.SERVER_BUSY
logging.exception("[UWEB] uid: %s tid: %s get terminal failed. Exception: %s",
self.current_user.uid, self.current_user.tid, e.args)
self.write_ret(status)
示例2: notify_report_by_sms
# 需要导入模块: from helpers.queryhelper import QueryHelper [as 别名]
# 或者: from helpers.queryhelper.QueryHelper import get_white_list_by_tid [as 别名]
def notify_report_by_sms(self, report, mobile):
flag = self.check_timestamp(int(report['timestamp']))
if not flag:
return
name = QueryHelper.get_alias_by_tid(report.dev_id, self.redis, self.db)
terminal_time = get_terminal_time(int(report['timestamp']))
terminal_time = safe_unicode(terminal_time)
report_name = report.name
if not report_name:
if report.cLon and report.cLat:
report_name = ErrorCode.ERROR_MESSAGE[ErrorCode.LOCATION_NAME_NONE]
else:
report_name = ErrorCode.ERROR_MESSAGE[ErrorCode.LOCATION_FAILED]
sms = ''
sms_white = ''
if isinstance(report_name, str):
report_name = report_name.decode('utf-8')
report_name = unicode(report_name)
if report.rName == EVENTER.RNAME.POWERLOW:
if report.terminal_type == "1": # type: terminal
if int(report.pbat) == 100:
pbat_message_key = get_pbat_message_key(report.dev_id)
if self.redis.exists(pbat_message_key) is False:
self.redis.setvalue(pbat_message_key, 1, time=24*60*60)
else:
logging.info("[EVENTER] Don't send duplicate power full message to terminal:%s in 24 hours", report.dev_id)
return
elif int(report.pbat) > 20 and int(report.pbat) < 100:
logging.info("[EVENTER] Terminal:%s reported power low pbat:%s between 20% and 100%, so skip it", report.dev_id, report.pbat)
return
sms = self.handle_power_status(report, name, report_name, terminal_time)
else: # type: fob
sms = SMSCode.SMS_FOB_POWERLOW % (report.fobid, terminal_time)
elif report.rName == EVENTER.RNAME.ILLEGALMOVE:
if report_name in [ErrorCode.ERROR_MESSAGE[ErrorCode.LOCATION_NAME_NONE], ErrorCode.ERROR_MESSAGE[ErrorCode.LOCATION_FAILED]]:
sms = SMSCode.SMS_ILLEGALMOVE_NOLOC % (name, terminal_time)
else:
sms = SMSCode.SMS_ILLEGALMOVE % (name, report_name, terminal_time)
_date = datetime.datetime.fromtimestamp(int(report['timestamp']))
_seconds = _date.hour * 60 * 60 + _date.minute * 60 + _date.second
if _seconds < 7 * 60 * 60 or _seconds > 19 * 60 * 60:
_resend_alarm = functools.partial(self.sms_to_user, report.dev_id, sms+u"重复提醒,如已收到,请忽略。", mobile)
#NOTE: re-notify
# 30 seconds later, send sms 1 time.
task = RepeatedTimer(30, _resend_alarm, 1)
task.start()
elif report.rName == EVENTER.RNAME.ILLEGALSHAKE:
if report_name in [ErrorCode.ERROR_MESSAGE[ErrorCode.LOCATION_NAME_NONE], ErrorCode.ERROR_MESSAGE[ErrorCode.LOCATION_FAILED]]:
sms = SMSCode.SMS_ILLEGALSHAKE_NOLOC % (name, terminal_time)
else:
sms = SMSCode.SMS_ILLEGALSHAKE % (name, report_name, terminal_time)
#NOTE: re-notify
_date = datetime.datetime.fromtimestamp(int(report['timestamp']))
_seconds = _date.hour * 60 * 60 + _date.minute * 60 + _date.second
if _seconds < 7 * 60 * 60 or _seconds > 19 * 60 * 60:
_resend_alarm = functools.partial(self.sms_to_user, report.dev_id, sms+u"此条短信为重复提醒,请注意您的车辆状态。", mobile)
# 30 seconds later, send sms 1 time.
task = RepeatedTimer(30, _resend_alarm, 1)
task.start()
elif report.rName == EVENTER.RNAME.EMERGENCY:
whitelist = QueryHelper.get_white_list_by_tid(report.dev_id, self.db)
if whitelist:
white_str = ','.join(white['mobile'] for white in whitelist)
if report_name in [ErrorCode.ERROR_MESSAGE[ErrorCode.LOCATION_NAME_NONE], ErrorCode.ERROR_MESSAGE[ErrorCode.LOCATION_FAILED]]:
sms = SMSCode.SMS_SOS_OWNER_NOLOC % (name, white_str, terminal_time)
sms_white = SMSCode.SMS_SOS_WHITE_NOLOC % (name, terminal_time)
else:
sms = SMSCode.SMS_SOS_OWNER % (name, white_str, report_name, terminal_time)
sms_white = SMSCode.SMS_SOS_WHITE % (name, report_name, terminal_time)
else:
if report_name in [ErrorCode.ERROR_MESSAGE[ErrorCode.LOCATION_NAME_NONE], ErrorCode.ERROR_MESSAGE[ErrorCode.LOCATION_FAILED]]:
sms = SMSCode.SMS_SOS_NOLOC % (name, terminal_time)
else:
sms = SMSCode.SMS_SOS % (name, report_name, terminal_time)
elif report.rName == EVENTER.RNAME.POWERDOWN:
if report_name in [ErrorCode.ERROR_MESSAGE[ErrorCode.LOCATION_NAME_NONE], ErrorCode.ERROR_MESSAGE[ErrorCode.LOCATION_FAILED]]:
sms = SMSCode.SMS_POWERDOWN_NOLOC % (name, terminal_time)
else:
sms = SMSCode.SMS_POWERDOWN % (name, report_name, terminal_time)
elif report.rName == EVENTER.RNAME.REGION_OUT:
if report_name in [ErrorCode.ERROR_MESSAGE[ErrorCode.LOCATION_NAME_NONE], ErrorCode.ERROR_MESSAGE[ErrorCode.LOCATION_FAILED]]:
sms = SMSCode.SMS_REGION_OUT_NOLOC % (name, safe_unicode(report['region']['region_name']), terminal_time)
else:
sms = SMSCode.SMS_REGION_OUT % (name, safe_unicode(report['region']['region_name']), report_name, terminal_time)
elif report.rName == EVENTER.RNAME.REGION_ENTER:
if report_name in [ErrorCode.ERROR_MESSAGE[ErrorCode.LOCATION_NAME_NONE], ErrorCode.ERROR_MESSAGE[ErrorCode.LOCATION_FAILED]]:
sms = SMSCode.SMS_REGION_ENTER_NOLOC % (name, safe_unicode(report['region']['region_name']), terminal_time)
else:
sms = SMSCode.SMS_REGION_ENTER % (name, safe_unicode(report['region']['region_name']), report_name, terminal_time)
elif report.rName == EVENTER.RNAME.SPEED_LIMIT:
sms_dct = dict(name=name,
report_name=report_name,
#.........这里部分代码省略.........