def GET(self): if xconfig.is_mute(): return dict(code="fail", message="mute") try: tm = time.localtime() if tm.tm_hour >= 0 and tm.tm_hour <= 6: return False if tm.tm_hour == 7 and tm.tm_min < 30: return False if tm.tm_min == 0: msg = "现在时间是%s点整" % tm.tm_hour else: msg = "现在时间是%s点%s分" % (tm.tm_hour, tm.tm_min) if tm.tm_hour >= 23: return False msg += ",夜深了,请注意休息" xutils.say(msg) # voice.Release() return dict(code="success", message="") except Exception as e: return dict(code="fail", message=str(e)) else: pass finally: pass
def GET(self, msg=None): repeat = xutils.get_argument("repeat", 3, type=int) content = xutils.get_argument("content") repeat = min(10, repeat) if msg is None: msg = content if xconfig.is_mute(): return dict(code="fail", message="mute") msg = xutils.unquote(msg) for i in range(repeat): xutils.say(msg) time.sleep(2) return dict(code="success")
def GET(self): city_code = xutils.get_argument("city_code", "101020100") city_name = xutils.get_argument("city_name", "上海") city_name = xutils.u(city_name) message = None db = xtables.get_record_table() record = db.select_one(where="type='weather' AND DATE(ctime)=$date_str AND key=$key", vars=dict(date_str=xutils.format_date(), key=city_name)) if record is not None: message = record.value else: url = "http://www.weather.com.cn/weather1d/%s.shtml" % city_code html = six.moves.urllib.request.urlopen(url).read() if html == b"<!-- empty -->": return dict(code="fail", message=u("city_code错误")) soup = BeautifulSoup(html, "html.parser") elements = soup.find_all(id="hidden_title") # print(elements) # print(len(html)) # return html if len(elements) > 0: weather = elements[0] message = weather.attrs["value"] message = message.replace("/", u("至")) db.insert(ctime=xutils.format_datetime(), cdate=xutils.format_date(), type="weather", key=city_name, value=message ) if message is not None: message = u(message) if not xconfig.is_mute(): xutils.say("%s %s" % (city_name, message)) # six.print_(type(message), message) return dict(code="success", data=message) else: return dict(code="fail", message="结果为空")