def index(): """ Pulling together different resources for the main kiosk page. Note that a lot of these are just initial values to populate the page. We'll have JS update them in real-time. Where do these come from? current_time - datetime module current location - ipinfo/openweather weather - openweather camera status - monitoring/camera wifi status - iw_parse plex - plexapi # notes # battery status? # water level? # what else? """ global message cam_status = 'on' if cam_thread else "off" weather = get_weather() # Strictly debugging: try: wdata = weather['weather'] except KeyError: print(weather) print('key: %s' % os.environ.get("OPENWEATHER_API_KEY")) templateData = { 'message': message, 'current_time': datetime.datetime.now(), 'cam_status': cam_status, 'weather': get_weather(), 'wifi': get_network_details(), 'on_deck': currently_watching(), 'unwatched': unwatched() } return render_template('index.html', **templateData)
def main(command): if 'hello' in command: talk("Hey I am Siri! How can I help you?") elif 'weather' in command: city = command.split()[-1] try: forecast = get_weather(city) except KeyError: talk('Sorry, I did not get the city. Please repeat again.') command = listen() talk( f"{forecast[0].capitalize()}. The temperature is {forecast[1]} degrees Celsius. " f"Humidity is {forecast[2]}. Sun rises at {forecast[3]} and sets at {forecast[4]}!" ) talk('What would you like to ask me next?') elif 'open' in command and 'google' in command and 'search for' in command: search = command[command.index('for') + 1:] url = 'https://www.google.com/' + f'/search?q={search}' webbrowser.open(url) talk('Bye') sys.exit() elif 'open google' in command: webbrowser.open('https://www.google.com/') talk('Bye') sys.exit() elif 'email' in command or 'gmail' in command or 'mail' in command: keys = talk_mail() receiver, text = keys[2], keys[3] try: send_mail(keys[0], keys[1], receiver, text) except smtplib.SMTPAuthenticationError: talk('Wrong login or password, wanna try again?') again = listen() if 'yes' in again: keys = talk_mail(extra=False) send_mail(keys[0], keys[1], receiver, text) elif 'no': sys.exit() elif 'thank you' in command: talk('It is my job, boss! Would you like to continue?') if 'yes' in listen(): talk('What would you like to ask me?') else: talk('bye') sys.exit() elif 'news' in command: talk( 'What country would you like to get the news for? United States or Ukraine?' ' Say a single word with country name please.') country = listen() news = get_news(pref=country, amount=5) while not news.isEmpty(): article = news.pop() talk(article.get_description(), country) talk('Would you like to open web page with this article or stop?') open_page = listen() if 'yes' in open_page: article.open_url() talk(f"Bye! Enjoy the article.") sys.exit() elif 'stop' in open_page: talk('What would you like to ask me?') break else: continue elif 'flip' in command and 'coin' in command: sides = ['head', 'tail'] talk(f'I flipped it for you! Landed on {sides[random.randint(0, 1)]}') talk('What would you like to ask me next?') elif 'calculate' in command or 'math' in command: talk('Please say your math expression') talk(calculate_expression(listen())) talk('What would you like to ask me next?') elif 'change' in command and 'name' in command: talk('Please say your name!') name = listen() talk(f'Nice to meet you, {name}') elif 'time' in command: named_tuple = time.localtime() time_string = time.strftime("%H:%M", named_tuple) talk(f"It's {time_string}.") talk('What would you like to ask me next?') elif 'date' in command: named_tuple = time.localtime() time_string = time.strftime("%d/%m/%Y", named_tuple) talk(f"It's {time_string}.") talk('What would you like to ask me next?') elif 'animal' in command: talk(read_answers('animal.txt')) talk('What would you like to ask me next?') elif 'boyfriend' in command: talk(read_answers('boyfriend.txt')) talk('What would you like to ask me next?') elif 'colour' in command: talk(read_answers('color.txt')) talk('What would you like to ask me next?') elif 'doing' in command: talk(read_answers('doing.txt')) talk('What would you like to ask me next?') elif 'dream' in command: talk(read_answers('dream.txt')) talk('What would you like to ask me next?') elif 'intelligent' in command: talk(read_answers('intelligent.txt')) talk('What would you like to ask me next?') elif 'kiss' in command: talk(read_answers('kiss.txt')) talk('What would you like to ask me next?') elif 'made' in command: talk(read_answers('made.txt')) talk('What would you like to ask me next?') elif 'old' in command: talk(read_answers('old.txt')) talk('What would you like to ask me next?') elif 'pets' in command: talk(read_answers('pets.txt')) talk('What would you like to ask me next?') elif 'robot' in command: talk(read_answers('robot.txt')) talk('What would you like to ask me next?') elif 'scared' in command: talk(read_answers('scared.txt')) talk('What would you like to ask me next?') elif 'wearing' in command: talk(read_answers('wearing.txt')) talk('What would you like to ask me next?') elif 'bye' in command or 'nothing' in command or \ 'go away' in command or 'goodbye' in command: talk('Bye') sys.exit() else: talk( 'Sorry I did not get it. Would you like to repeat? Say Yes or No.') if 'yes' in listen(): talk('I am listening') elif 'no' in listen(): talk('bye') sys.exit() else: talk('What would you like to ask me?')
""" THIS FILE WILL BE CHANGED IN THE FUTURE. FOR NOW THERE ARE SOME TESTING LINES. """ from modules import uni_converter, weather, spotify, speech_recognition print(str(uni_converter.feetsToMeters(6)) + ' m') print(str(uni_converter.inchesToCentimeters(6)) + ' cm') weather.get_weather('Gdansk')
def run(city): """ Get local news straight to the terminal """ # Pull in city information if not specified if not city: city = get_location() validate_city(city) # Print header print(""" _ _ ______ __ __ ______ | \ | || ____|\ \ / /|___ / | \| || |__ \ \ /\ / / / / | . ` || __| \ \/ \/ / / / | |\ || |____ \ /\ / / /__ |_| \_||______| \/ \/ /_____| """) print("\n Today's Newz: " + city) # Retrieve local forecast and format it response = weather.get_weather(city, WEATHER_KEY) forecast = weather.format_data(response) # Grab stock data stock_data = get_stock_data() # Pull in top three local news stories from Yahoo stories = articles.get_articles(city) # Combines weather and stock sections ws_section = format_weather_stock_section(forecast, stock_data) # Display newz print( """ ------------------------------------------------------------------------------------------------------------------------- | Local Weather | Finance | ------------------------------------------------------------------------------------------------------------------------- """ + ws_section + """ ------------------------------------------------------------------------------------------------------------------------- | Headlines | ------------------------------------------------------------------------------------------------------------------------- """ + str(stories[0][0]) + """ | | """ + str(stories[0][1]) + """ | | |-----------------------------------------------------------------------------------------------------------------------| """ + str(stories[1][0]) + """ | | """ + str(stories[1][1]) + """ | | |-----------------------------------------------------------------------------------------------------------------------| """ + str(stories[2][0]) + """ | | """ + str(stories[2][1]) + """ | | | | ------------------------------------------------------------------------------------------------------------------------- """)
def processRequest(req): # Parsing the POST request body into a dictionary for easy access. req_dict = json.loads(request.data) # Accessing the fields on the POST request boduy of API.ai invocation of the webhook intent = req_dict["queryResult"]["intent"]["displayName"] print(f"INTENT = {intent}") if intent == 'weather': weather_location = str() if req_dict["queryResult"]["parameters"]["geo-city"]: weather_location = req_dict["queryResult"]["parameters"][ "geo-city"] else: weather_location = req_dict["queryResult"]["parameters"][ "geo-country"] res = weather.get_weather(weather_location) elif intent == 'world-clock': if req_dict["queryResult"]["parameters"]["geo-city"]: clock_location = req_dict["queryResult"]["parameters"]["geo-city"] else: clock_location = req_dict["queryResult"]["parameters"][ "geo-country"] res = time.get_time(clock_location) # Knowledge Base elif "Knowledge.KnowledgeBase" in intent: res = { "fulfillmentMessages": [ { "text": { "text": [req_dict['queryResult']['fulfillmentText']] } }, ], } # Personal Files/Links elif intent == 'resume': res = { "fulfillmentMessages": [ { "text": { "text": [ f"https://tansawit.me/sawit-trisirisatayawong-resume.pdf" ] } }, ], } elif intent == 'linkedin': res = { "fulfillmentMessages": [ { "text": { "text": [f"https://www.linkedin.com/in/tansawit/"] } }, ], } elif intent == 'instagram': res = { "fulfillmentMessages": [{ "text": { "text": [ f"https://www.instagram.com/tansawit/", ], }, }, { "text": { "text": [f"https://www.instagram.com/sawittan/"], } }], } # TEST elif intent == 'directions': directions_type, directions_location = \ next((k, v) for k, v in req_dict["queryResult"] ["parameters"]["location"].items() if v) res = directions.get_directions(directions_location.replace( ' ', '%20')) elif intent == 'showing': res = showing.get_showing() elif intent == 'test': res = { "fulfillmentMessages": [{ "payload": { "line": { "altText": "Message", "type": "flex", "contents": { "type": "carousel", "contents": [{ "type": "bubble", "hero": { "type": "image", "url": "https://cdn.majorcineplex.com/uploads/movie/2601/thumb_2601.jpg?1571964618", "size": "full", "aspectMode": "cover", "action": { "type": "uri", "uri": "http://linecorp.com/" }, "aspectRatio": "3:4", "gravity": "bottom" }, "body": { "type": "box", "layout": "vertical", "contents": [{ "type": "text", "text": "Frozen 2", "weight": "bold", "size": "xl" }, { "type": "box", "layout": "vertical", "margin": "lg", "spacing": "sm", "contents": [{ "type": "text", "text": "วันที่เข้าฉาย: 21/11/19", "style": "normal", "weight": "bold" }] }] }, "footer": { "type": "box", "layout": "vertical", "spacing": "sm", "contents": [{ "type": "button", "style": "link", "height": "sm", "action": { "type": "postback", "label": "Description", "data": "Frozen" } }, { "type": "button", "style": "link", "height": "sm", "action": { "type": "uri", "label": "WEBSITE", "uri": "https://linecorp.com" } }, { "type": "spacer", "size": "sm" }], "flex": 0 } }, { "footer": { "type": "box", "layout": "vertical", "spacing": "sm", "flex": 0, "contents": [{ "style": "link", "height": "sm", "action": { "type": "uri", "uri": "https://linecorp.com", "label": "CALL" }, "type": "button" }, { "style": "link", "height": "sm", "action": { "type": "uri", "uri": "https://linecorp.com", "label": "WEBSITE" }, "type": "button" }, { "type": "spacer", "size": "sm" }] }, "hero": { "url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/01_1_cafe.png", "action": { "type": "uri", "uri": "http://linecorp.com/" }, "type": "image", "aspectRatio": "20:13", "size": "full", "aspectMode": "cover" }, "body": { "type": "box", "layout": "vertical", "contents": [{ "type": "text", "text": "Brown Cafe", "weight": "bold", "size": "xl" }, { "margin": "md", "type": "box", "layout": "baseline", "contents": [{ "url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png", "size": "sm", "type": "icon" }, { "type": "icon", "url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png", "size": "sm" }, { "type": "icon", "url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png", "size": "sm" }, { "type": "icon", "url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png", "size": "sm" }, { "type": "icon", "url": "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gray_star_28.png", "size": "sm" }, { "text": "4.0", "type": "text", "size": "sm", "color": "#999999", "margin": "md", "flex": 0 }] }, { "margin": "lg", "type": "box", "layout": "vertical", "spacing": "sm", "contents": [{ "type": "box", "layout": "baseline", "spacing": "sm", "contents": [{ "flex": 1, "size": "sm", "color": "#aaaaaa", "type": "text", "text": "Place" }, { "type": "text", "text": "Miraina Tower, 4-1-6 Shinjuku, Tokyo", "size": "sm", "color": "#666666", "flex": 5, "wrap": True }] }, { "contents": [{ "size": "sm", "color": "#aaaaaa", "type": "text", "text": "Time", "flex": 1 }, { "type": "text", "text": "10:00 - 23:00", "size": "sm", "color": "#666666", "flex": 5, "wrap": True }], "type": "box", "layout": "baseline", "spacing": "sm" }] }] }, "type": "bubble" }] } } }, }] } return res