def update_feels_like(self): parsed_json = weather.fetchWeather('conditions') weather.closeURL() NOW_URL = "https://icons.wxug.com/i/c/v4/" + parsed_json['current_observation']['icon'] + ".svg" NOW_Feel = float(parsed_json['current_observation']['feelslike_f']) now = Now.get() now.Now_URL = NOW_URL now.Now_Feel = NOW_Feel logging.getLogger("thread-feels").info(" Updated feels like info.")
def update_feels_forecast(self): parsed_json = weather.fetchWeather('forecast') weather.closeURL() NOW_Feel_High = float(parsed_json['forecast']['simpleforecast']['forecastday'][0]['high']["fahrenheit"]) NOW_Feel_Low = float(parsed_json['forecast']['simpleforecast']['forecastday'][0]['low']["fahrenheit"]) now = Now.get() now.Now_Feel_High = NOW_Feel_High now.NOW_Feel_Low = NOW_Feel_Low logging.getLogger("thread-feels").info(" Updated high-low data.")
def update_feels_like(self): parsed_json = weather.fetchWeather('conditions') weather.closeURL() NOW_URL = "https://icons.wxug.com/i/c/v4/" + parsed_json[ 'current_observation']['icon'] + ".svg" NOW_Feel = float(parsed_json['current_observation']['feelslike_f']) now = Now.get() now.Now_URL = NOW_URL now.Now_Feel = NOW_Feel logging.getLogger("thread-feels").info(" Updated feels like info.")
def update_feels_forecast(self): parsed_json = weather.fetchWeather('forecast') weather.closeURL() NOW_Feel_High = float(parsed_json['forecast']['simpleforecast'] ['forecastday'][0]['high']["fahrenheit"]) NOW_Feel_Low = float(parsed_json['forecast']['simpleforecast'] ['forecastday'][0]['low']["fahrenheit"]) now = Now.get() now.Now_Feel_High = NOW_Feel_High now.NOW_Feel_Low = NOW_Feel_Low logging.getLogger("thread-feels").info(" Updated high-low data.")
def home(): city = request.args.get("city") if request.args.get('btn') == "查询": try: result = retrieve_data(city) return render_template('weather.html', result=result) except TypeError: try: location, weather, temper, day = fetchWeather(city) insert_data(location, weather, temper, day) result = ''' 地点: {}, 天气: {}, 温度: {}, 更新时间: {}/n'''.format(location, weather, temper, day) return render_template('weather.html', result=result) except KeyError: result = "Invalid command. Type 'help' to check the available commands." return render_template('404.html', result=result) elif request.args.get('btn') == "帮助": return render_template('help.html') elif request.args.get('btn') == "历史": history = get_history() return render_template('history.html', result=history) elif request.args.get('btn') == "更新": try: location, weather = city.split(' ') weather_list = ["晴", "小雨", "大雨", "阴天", "大雪", "中雪", "小雪"] if weather in weather_list: update(location, weather) return render_template('update.html') else: result = "请正确输入信息,例如:[北京 多云]" return render_template('404.html', result=result) except ValueError: result = "Invalid command. Type 'help' to check the available commands." return render_template('404.html', result=result) else: result = "Invalid command. Type 'help' to check the available commands." return render_template('404.html', result=result)
def work_card(msg): wel_content = u"""欢迎关注vuurwerke! 1. 回复'1'或者'打卡', 记录今天的上班时间 2. 回复'2'或者'下班', 记录今天的下班时间 3. 回复'3'查看今天的打卡记录 4. 回复'joke'查看今天的糗事百科 5. 回复'weather'查看今天天气 6. 回复'stock CTRP'查看股票信息(仅支持美股) 7. 回复'hot'查看百度热词榜 .. 'h'|'help', 随时查看帮助 """ # 设置返回数据模板 # 纯文本格式 #textTpl = """<xml> # <ToUserName><![CDATA[%s]]></ToUserName> # <FromUserName><![CDATA[%s]]></FromUserName> # <CreateTime>%s</CreateTime> # <MsgType><![CDATA[text]]></MsgType> # <Content><![CDATA[%s]]></Content> # <FuncFlag>0</FuncFlag> # </xml>""" textTpl = """<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content><![CDATA[%s]]></Content> <FuncFlag>0</FuncFlag> </xml>""" # 图文格式 pictextTpl = """<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[news]]></MsgType> <ArticleCount>1</ArticleCount> <Articles> <item> <Title><![CDATA[%s]]></Title> <Description><![CDATA[%s]]></Description> <PicUrl><![CDATA[%s]]></PicUrl> <Url><![CDATA[%s]]></Url> </item> </Articles> <FuncFlag>1</FuncFlag> </xml> """ # 判断MsgType内容,如果是一条“subscribe”的event,表明是一个新关注用户,如果不是,就判断内容 if msg["MsgType"] == "event": if msg["Event"] == "CLICK": if msg["EventKey"] in [u'onwork', u'offwork', u'worklist']: Content = deal_with_action(msg['EventKey'], msg['FromUserName']) echostr = textTpl % ( msg['FromUserName'], msg['ToUserName'], str(int(time.time())),Content) if msg["EventKey"] == "joke": echostr = joke.fetchJoke(msg) if msg["EventKey"] == "hot": echostr = baiduhot.fetchBaiduHot(msg) if msg["EventKey"] == "weather": echostr = weather.fetchWeather(msg) if msg["EventKey"] == "xiache": echostr = xiache.fetchzhihuXiache(msg) if msg["EventKey"] == "stock": tmpstr = "目前尚不支持点击操作,请手动输入'stock STOCK_NAME'处理" echostr = textTpl % ( msg['FromUserName'], msg['ToUserName'], str(int(time.time())),tmpstr) if msg["EventKey"] == "help": echostr = textTpl % ( msg['FromUserName'], msg['ToUserName'], str(int(time.time())),wel_content) else: echostr = textTpl % ( msg['FromUserName'], msg['ToUserName'], str(int(time.time())),wel_content) return echostr else: if msg['Content'].lower() in ['h', 'H', 'Help', 'help', u'帮助']: echostr = textTpl % ( msg['FromUserName'], msg['ToUserName'], str(int(time.time())),wel_content) #return echostr elif msg['Content'].lower() in ['joke', 'Joke', u'笑话', u'开心']: echostr = joke.fetchJoke(msg) #return echostr elif msg['Content'].lower() in ['weather', 'Weather', u'天气']: echostr = weather.fetchWeather(msg) elif msg['Content'].lower() in ['hot', 'baidu', u'百度', u'热点', u'新闻']: echostr = baiduhot.fetchBaiduHot(msg) elif msg['Content'].lower() in ['xiache', 'zhihu', u'知乎', u'tucao', u'吐槽', u'瞎扯']: echostr = xiache.fetchzhihuXiache(msg) elif msg['Content'].strip().lower().startswith('stock'): echostr = stock.fetchStock(msg) else: Content = deal_with_action(msg['Content'], msg['FromUserName']) echostr = textTpl % ( msg['FromUserName'], msg['ToUserName'], str(int(time.time())),Content) #return echostr return echostr
confidence = {} print("taking picture now.") # pic = capture_pic() pic = "test1.jpg" faceId1 = upload_img(pic) # faceId1 = upload_img('test4.jpg') confidence['yang'] = compare(faceId1, yangId) confidence['wu'] = compare(faceId1, heId) confidence['he'] = compare(faceId1, wuId) flag = False for key, val in confidence.items(): print(key, val) if val > 80: print(key + " is checked.") weather, temp = fetchWeather("成都") print("今天的天气是%s, 现在的温度是%s摄氏度." % (weather, temp)) flag = True break if flag == False: print("nobody is checked. please check again.") def test(filename): classifier = cv2.CascadeClassifier("haarcascade_frontalface_alt2.xml") frame = cv2.imread(filename) grey = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) # 转为灰度图象 faceRects = classifier.detectMultiScale(grey, scaleFactor=1.2, minNeighbors=3, minSize=(32, 32))