本文整理汇总了Python中util.Util.cn2dig方法的典型用法代码示例。如果您正苦于以下问题:Python Util.cn2dig方法的具体用法?Python Util.cn2dig怎么用?Python Util.cn2dig使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类util.Util
的用法示例。
在下文中一共展示了Util.cn2dig方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: callback
# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import cn2dig [as 别名]
def callback(self, cmd, action, target, msg):
if msg is None:
self._home.publish_msg(cmd, u"时间格式错误")
return False, None
if msg.endswith(u'点') or \
msg.endswith(u'分'):
t = Util.gap_for_timestring(msg)
elif msg.endswith(u"秒"):
t = int(Util.cn2dig(msg[:-1]))
elif msg.endswith(u"分钟"):
t = int(Util.cn2dig(msg[:-2]))*60
elif msg.endswith(u"小时"):
t = int(Util.cn2dig(msg[:-2]))*60*60
else:
self._home.publish_msg(cmd, u"时间格式错误")
return False
if t is None:
self._home.publish_msg(cmd, u"时间格式错误")
return False, None
DEBUG("thread wait for %d sec" % (t, ))
self._home.publish_msg(cmd, action + target + msg)
threading.current_thread().waitUtil(t)
if threading.current_thread().stopped():
return False
self._home.setResume(True)
count = 7
Sound.play( Res.get_res_path("sound/com_bell") , True, count)
self._home.setResume(False)
return True
示例2: callback
# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import cn2dig [as 别名]
def callback(self, cmd, delay_time, action, target, msg):
if delay_time is None or len(delay_time) == 0:
self._home.publish_msg(cmd, u"时间格式错误")
return False, None
t = None
if delay_time.endswith(u"秒") or delay_time.endswith(u"秒钟"):
t = int(Util.cn2dig(delay_time[:-1]))
elif delay_time.endswith(u"分钟"):
t = int(Util.cn2dig(delay_time[:-2])) * 60
elif delay_time.endswith(u"小时"):
t = int(Util.cn2dig(delay_time[:-2])) * 60 * 60
else:
t = Util.gap_for_timestring(delay_time)
if t is None:
WARN("error delay_time format")
self._home.publish_msg(cmd, u"时间格式错误:" + delay_time)
return False, None
info = delay_time + u"执行: %s%s%s" % (Util.xunicode(action), Util.xunicode(target), Util.xunicode(msg))
# self._home.publish_msg(cmd, info) # noise
DEBUG("delay wait for %d sec" % (t,))
threading.current_thread().waitUtil(t)
if threading.current_thread().stopped():
return False
return True
示例3: callback
# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import cn2dig [as 别名]
def callback(self, msg):
num = Util.cn2dig(msg)
if num is None:
ERROR("num_value_callback num is invaild:" + msg)
return False
else:
return True, float(num)
示例4: _parse_expression
# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import cn2dig [as 别名]
def _parse_expression(self, tokens):
expression = u''
for token in tokens:
if token in cal_callback._ops:
expression += cal_callback._ops[token]
else:
num = Util.cn2dig(token)
if num is None:
return None
expression += str(num)
res = None
INFO("expression: " + expression)
try:
res = eval(expression)
res = Decimal.from_float(res).quantize(Decimal('0.00'))
except Exception, ex:
ERROR("cal expression error:", ex)