コード例 #1
0
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""

@author: Tanmay
"""
########## News API ########################################################
from newsapi import NewsAPI

key = '96af62a035db45bda517a9ca62a25ac3'
params = {}
api = NewsAPI(key)
sources = api.sources(params)
articles = api.articles(sources[0]['id'], params)

################ NY Times API #############################################

import sys, csv, json
reload(sys)
sys.setdefaultencoding('utf8')

import requests
"""
About:
Python wrapper for the New York Times Archive API 
https://developer.nytimes.com/article_search_v2.json
"""


class APIKeyException(Exception):
    def __init__(self, message):
コード例 #2
0
def ai(data):
    #greet
    if "how are you" in data:
        speak('I am fine')
        gui('I am fine')
        
 
    #time
    elif any(x in data for x in c):
        speak(ctime())
        gui(ctime())
        
 
    #location
    elif "where is" in data:
        data = data.split(" ")
        location = data[2]
        print("Hold on, I will show you where " + location + " is.")
        speak("Hold on, I will show you where " + location + " is.")
        
        webbrowser.open('https://www.google.co.in/maps/place/{}'.format(location), new=2) 
        time.sleep(10)
    #website
    elif "open" and "browser" in data:
        data = data.split(" ")
        site=data[1]
        print("Hold on, I will open " + site)
        speak("Hold on, I will open " + site)
        webbrowser.open('https://www.{}.com'.format(site), new=2)
        time.sleep(10)

    
    #solve
    elif 'solve' in data:
        try:
            data=data.split('solve',1)
            k=data[1].replace(' x ','*')
            k=k.replace('raise to power','**')
            speak('the solution is '+str(eval(k)))
            gui('The soluton is '+str(eval(k)))
        except Exception as e:
            print(e)
            time.sleep(5)


    #news
    elif 'news' in data:
        params = {}
        api = NewsAPI('a7d10f7638cc4644a05cf344401a81fd')

        #india

        news_str='India\n'
        articles = api.articles('the-times-of-india', params)
        for i in articles:
            analysis=TextBlob(i['title'])
            news_str=news_str+'-'+i['title']
            if analysis.sentiment.polarity < 0:
                news_str=news_str+' :(\n'
            elif analysis.sentiment.polarity > 0:
                news_str=news_str+' :)\n'
            else:
                news_str=news_str+' :|\n'
                
        #world
        news_str=news_str+"\nWorld\n"
        articles = api.articles('bbc-news', params)
        for i in articles:
            analysis=TextBlob(i['title'])
            news_str=news_str+'-'+i['title']
            if analysis.sentiment.polarity < 0:
                news_str=news_str+' :(\n'
            elif analysis.sentiment.polarity > 0:
                news_str=news_str+' :)\n'
            else:
                news_str=news_str+' :|\n'
        gui(news_str)