def main(): matrix = InfoMatrix() last_weather_reading = timestamp() weather = weather_info() while True: if timestamp() - last_weather_reading >= WEATHER_INTERVAL: weather = weather_info() last_weather_reading = timestamp() matrix.update_weather(weather["temperature"], weather.get("precipType", "None")) time.sleep(CHANGE_INTERVAL) buses = bus_info() for route, predictions in buses.iteritems(): next_bus = predictions[0] if predictions else "None" matrix.write_bus(route, next_bus) time.sleep(CHANGE_INTERVAL)
def main(): matrix = InfoMatrix() last_weather_reading = timestamp() weather = weather_info() while True: if timestamp() - last_weather_reading >= WEATHER_INTERVAL: weather = weather_info() last_weather_reading = timestamp() matrix.update_weather(weather['temperature'], weather.get('precipType', 'None')) time.sleep(CHANGE_INTERVAL) buses = bus_info() for route, predictions in buses.iteritems(): next_bus = predictions[0] if predictions else 'None' matrix.write_bus(route, next_bus) time.sleep(CHANGE_INTERVAL)
def home(): if request.method == 'POST': city = request.form['city'] units = request.form['units'] info = weather_info(city, units) quote = quotes_info() return render_template('home.html', title='homepage', info=info, quote=quote) return render_template('home.html', title='homepage')
def text_reply(msg): if msg["ToUserName"] == "filehelper": if msg.text[:3] == "cmd": os.system(msg.text[4:]) if msg.text[:3] == "del": char = msg.text[4:] # print(char) delete_word(char) if msg.text[:3] == "add": char = msg.text[4:] # print(char) add_word(char) if msg.text[:5] == "query": sql_str = msg.text[6:] itchat.send_msg(str(computer_query(sql_str)), toUserName='******') if msg.text[:2] == "天气": itchat.send_msg(weather_info(), toUserName='******')
def get_message(bot, update): if "코인" in update.message.text: print(update.message.text) param = {'coin_name': ''} coin_val = coin_info(**param) update.message.reply_text("%s" % coin_val, reply_markup=reply_markup) if "날씨" in update.message.text: print(update.message.text) update.message.reply_text("날씨", reply_markup=reply_markup2) if "죽전동" in update.message.text or "강남역" in update.message.text: print(update.message.text) params = {'area': update.message.text} msg = weather_info(**params) update.message.reply_text("%s" % msg, reply_markup=reply_markup2) # 날짜와 시간 if update.message.text == "날짜": print(update.message.text) now = datetime.datetime.now() update.message.reply_text("오늘의 날짜 : \n%s년 %s월 %s일 입니다." % (now.year, now.month, now.day)) if update.message.text == "시간": print(update.message.text) now = datetime.datetime.now() update.message.reply_text("현재 시간 : \n%s시 %s분 %s초 입니다." % (now.hour, now.minute, now.second)) if update.message.text == "아이디": chat_id = update.message.chat_id update.message.reply_text("당신의 chat_id 는 %s 입니다." % chat_id, reply_markup=reply_markup) if update.message.text == "처음으로": print(update.message.text) update.message.reply_text("처음으로", reply_markup=reply_markup)
def message(): resp = request.get_json() content = resp['content'] if content == '코인': print('=>코인') param = {'coin_name': 'ALL'} message = { 'message': { 'text': coin_info(**param) }, 'keyboard': { 'type': 'buttons', 'buttons': mylist1 } } elif content == '날씨': print('날씨') message = { 'message': { 'text': '날씨를 선택하세요' }, 'keyboard': { 'type': 'buttons', 'buttons': mylist2 } } elif content.find('강남역') != -1: print('강남역 날씨') params = {'area': content} msg = weather_info(**params) message = { 'message': { 'text': msg }, 'keyboard': { 'type': 'buttons', 'buttons': mylist2 } } elif content.find('죽전동') != -1: print('죽전동 날씨') params = {'area': content} msg = weather_info(**params) message = { 'message': { 'text': msg }, 'keyboard': { 'type': 'buttons', 'buttons': mylist2 } } elif content.find('번역') != -1: print('번역') msg = '구현 예정입니다' message = { 'message': { 'text': msg }, 'keyboard': { 'type': 'buttons', 'buttons': mylist1 } } elif content == '처음으로': print('==>처음으로') return jsonify({ 'message': { 'text': '선택해 주세요' }, 'keyboard': { 'type': 'buttons', 'buttons': mylist1 } }) else: message = { 'message': { 'text': '잘못된 입력입니다' }, 'keyboard': { 'type': 'buttons', 'buttons': mylist1 } } return jsonify(message)
def get_bot_response(): userText = request.args.get('msg') return str(weather.weather_info(userText))
def get_weather_info(city): return weather_info(city, owm_api)
from bot import telegram_chatbot from weather import weather_info bot = telegram_chatbot("telegram_config.cfg") wi = weather_info("owm_config.cfg") def make_reply(message): reply = None if message is not None: stats = wi.get_info(message) if message in ("/start", "/help"): reply = "Enter a city name in chat to get its real time weather stats\nSend '/help' in case of unexpected behaviour or difficulties\n\nNote: Make sure you enter a 'valid city name' and not any state or country name, doing so will result in improper replies" return reply if str(stats["cod"]) == "404": return "City not found. Enter a valid city name" reply = [] reply.append(stats["name"]) reply.append(f"Description: {stats['weather'][0]['description']}") reply.append( f"Temperature(celcius): {round(stats['main']['temp'] - 273.15, 2)}") reply.append( f"Max Temperature(celcius): {round(stats['main']['temp_max'] - 273.15, 2)}" ) reply.append( f"Min Temperature(celcius): {round(stats['main']['temp_min'] - 273.15, 2)}" ) reply.append(f"Humidity(percent): {stats['main']['humidity']}") reply.append(f"Pressure(hPa): {stats['main']['pressure']}") reply = "\n".join(reply) return reply
from bot import telegram_chatbot from weather import weather_info bot = telegram_chatbot('telegram_config.cfg') wi = weather_info('owm_config.cfg') def make_reply(message): reply = None if message is not None: stats = wi.get_info(message) if message in ('/start', '/help'): reply = "Enter a city name in chat to get its real time weather stats\nSend '/help' in case of unexpected behaviour or difficulties\n\nNote: Make sure you enter a 'valid city name' and not any state or country name, doing so will result in improper replies" return reply if str(stats['cod']) == '404': return 'City not found. Enter a valid city name' reply = [] reply.append(stats['name']) reply.append(f"Description: {stats['weather'][0]['description']}") reply.append(f"Temperature(celcius): {round(stats['main']['temp'] - 273.15, 2)}") reply.append(f"Max Temperature(celcius): {round(stats['main']['temp_max'] - 273.15, 2)}") reply.append(f"Min Temperature(celcius): {round(stats['main']['temp_min'] - 273.15, 2)}") reply.append(f"Humidity(percent): {stats['main']['humidity']}") reply.append(f"Pressure(hPa): {stats['main']['pressure']}") reply = '\n'.join(reply) return reply update_id = None while True: print('...') updates = bot.get_updates(offset=update_id) updates = updates['result']
def main(): number = 0 #lcd_init() th_flag = False display_update = False index = 0 w = weather.weather_info("seoul") music_thread = music.MusicThread() music_thread.start() display_on = display.Display() weather_list = [w['date'], w['temp'], w['location'], w['weather']] music_list = ['None', 'None'] display_on.set_info(weather_list, music_list) display_on.start() print("start loop") while True: number = getch.getch() #print(number) if (number == '1'): display_update = True w = weather.weather_info("seoul") elif (number == '2'): display_update = True w = weather.weather_info("london") elif (number == '3'): display_update = True w = weather.weather_info("newyork") elif (number == 'a'): index = 0 display_update = True th_flag = not th_flag music_thread.push_power_switch() elif (number == '4'): music_thread.pause() elif (number == '5'): music_thread.unpause() elif (number == 'b'): index = index + 1 display_update = True music_thread.play_next_music() elif (number == 'p'): music_thread.volume_up() elif (number == '-'): music_thread.volume_down() elif (number == '8'): music_thread.exit() display_on.exit() exit() if (display_update == True): print("display update...") weather_list = [w['date'], w['temp'], w['location'], w['weather']] music_list = music_thread.get_current_info(index % 3) display_on.set_info(weather_list, music_list) display_update = False