コード例 #1
0
ファイル: program.py プロジェクト: sshacker/JARVIS
def program(query):
    """
			TO SEARCH THE PROGRAM IN WINDOWS SEARCH-BAR AND OPEN IT
	"""
    #LIST OF EACH WORD IN QUERY
    word_list = query.split()

    #TO FIND PROGRAM NAME
    i = word_list.index("OPEN")
    query = word_list[i + 1]

    #TO STRAT SEARCHING
    response = "start searching for " + query
    print(response)
    speaker.speak(response)

    #TO OPEN SEARCH BAR FOR SEARCH A PROGRAM
    p.keyDown("win")
    p.press("s")
    p.keyUp("win")

    #TO WRITE THE GIVEN QUERY
    key.write_query(query)

    #PRESS ENTER
    p.press("enter")

    #OPENING THE PROGRAM
    q = query + " is opening."
    print(q)
    speaker.speak(q)

    #do somethings below with opened program
    #...
    return
コード例 #2
0
def take_text_command():
    """
        [ TAKE TEXT INPUT FROM USER AND RETURN INPUT AS QUERY ]
    """
    print("\nJARVIS :- ")
    
    #REQUEST USER TO GIVE COMMAND 
    response = "command me sir..."
    print(response)
    speaker.speak(response)

    #TO TAKE INPUT IN QUERY
    query = input("YOU : ")
    query = query.upper()
    
    #TO CHECK IF TERMINATE COMMAND FOR PROGRAM
    if query.replace(" ","") in variables.terminate :
        response = "HAVE A NICE DAY SIR ! BYE !!"
        print(response)
        speaker.speak(response)
        
        #FOR EXIT THE PROGRAM
        exit()
    
    #RETURN THE INPUT AS QUERY
    return query
コード例 #3
0
ファイル: music.py プロジェクト: lucifer1799/Project_Jarvis
def music(query):
    music_dir = 'F:\\vikash\\fav music'
    songs = os.listdir(music_dir)
    for i in songs:
        print(i)
    st = "which one you want to play :"
    print(st)
    speaker.speak(st)
    n = int(input())
    os.startfile(os.path.join(music_dir, songs[n - 1]))
コード例 #4
0
ファイル: bot.py プロジェクト: sshacker/JARVIS
def chat_bot_reply(query, kernel):
    """
        [ TAKE TWO INPUT QUERY AND KERNEL INSTANCE AND RETURN NOTHING ]
    """
    #GET REPLY FOR QUERY FROM AIML FILES
    bot_reply = kernel.respond(query.upper())

    print("CHAT BOT :- ")
    print(bot_reply)
    speaker.speak(bot_reply)

    return
コード例 #5
0
def wish_me(user):
    #TIME IN HOUR
    hour = int(datetime.datetime.now().hour)

    print("\nJARVIS :- ")

    #FOR GOOD MORNING
    if hour >= 0 and hour < 12:
        response = "good morning !"
        print(response)
        speaker.speak(response)

    #FOR GOOD AFTER-NOON
    elif hour >= 12 and hour < 18:
        response = "good afternoon !"
        print(response)
        speaker.speak(response)

    #FOR GOOD EVENING
    else:
        response = "good evening !"
        print(response)
        speaker.speak(response)

    response = "I am JARVIS sir. How may I help you?"
    print(response)
    speaker.speak(response)
    return
コード例 #6
0
def take_voice_command():
    """
        [ TO TAKE VOICE COMMAND INPUT FROM USER ]
    """
    #INSTANCE OF SPEECH RECOGNIZER
    r = sr.Recognizer()

    #TAKING SPEECH USING MICROPHONE
    with sr.Microphone() as source:
        print("\nlistening...")
        speaker.speak("command me sir...")

        #ADJUST FOR BACKGROUND NOISE
        r.adjust_for_ambient_noise(source)

        #LISTENING FROM MICROPHONE AS SOURCE
        audio = r.listen(source)
    try:
        #USING GOOGLE SPEECH RECOGNITION CONVERT VOICE-TO-TEXT
        query = r.recognize_google(audio)
        query = query.upper()

        print("\nYOU :- ")
        print(query.lower())

        #CLOSE THE PROGRAM IF A TERMINATE COMMAND FROM USER
        if query.replace(" ", "") in variables.terminate:
            print("HAVE A NICE DAY SIR ! BYE !!")
            speaker.speak("HAVE A NICE DAY SIR ! BYE !!")
            exit()

        #RETURN VOICE INPUT FROM USER IN TEXT FORM
        return query

    #FOR UN-KNOWN VALUE ERROR OR VOICE COULD NOT DETECTED CLEARLY
    except sr.UnknownValueError:
        print("\nJARVIS :- ")
        print(
            "I couldn't understand what you said! Would you like to repeat ?")
        speaker.speak(
            "I couldn't understand what you said! Would you like to repeat ?")

        #AGAIN CALL FOR VOICE INPUT FROM USER
        return take_voice_command()

    #FOR INTERNET CONNECTION ERROR OR REQUEST ERROR FROM SERVER
    except sr.RequestError as e:
        print("Please check your Internet Connection.")
        print("Could not request results from " +
              "Google Speech Recognition service; {0}".format(e))
        speaker.speak("Could not request results from " +
                      "Google Speech Recognition service; {0}".format(e))

        return take_voice_command()

    return
コード例 #7
0
def mail(query):
    try:
        speaker.speak("What should I say?")
        content = input()
        to = "*****@*****.**"
        sendEmail(to, content)
        speaker.speak("Email has been sent!")
    except Exception as e:
        print(e)
        speaker.speak(
            "Sorry my friend harry bhai. I am not able to send this email")
コード例 #8
0
def jarvis_reply(query):
    """
		TAKE A QUERY AND TO PERFORM A TASK ACCORDING TO QUERY
	"""

    #TASK TO YOUTUBE SEARCH
    if 'WIKIPEDIA' in query:
        speaker.speak('Searching Wikipedia...')
        query = query.replace("wikipedia", "")
        results = wikipedia.summary(query, sentences=2)
        speaker.speak("According to Wikipedia")
        print(results)
        speaker.speak(results)
    if "YOUTUBE" in query:
        webbrowser.open("youtube.com")
        #return youtube.youtube(query)

        #TASK TO FACEBOOK SEARCH
    if "FACEBOOK" in query:
        webbrowser.open("facebook.com")
        #return facebook.facebook(query)

    #TASK TO GOOGLE SEARCH
    elif "default" in query:
        return google.google(query)

#TASK TO OPEN PROGRAM
    elif "OPEN" in query:
        return program.program(query)

    #DO SOMETHINGS FOR OTHER TASKS

    elif 'PLAY MUSIC' in query:
        return music.music(query)

    elif 'SEND MAIL' in query:
        return mail.mail(query)
    elif 'VIDEO SONG' in query:
        return video.video(query)
    elif 'CHANGE WALLPAPER' in query:
        return wallpaper.wallpaper(query)
    elif 'SEARCH GOOGLE' in query:
        webbrowser.open("google.com")
    elif 'SEARCH STACKOVERFLOW' in query:
        webbrowser.open("stackoverflow.com")

    return
コード例 #9
0
ファイル: facebook.py プロジェクト: sshacker/JARVIS
def facebook(query):

    driver = webdriver.Chrome()
    driver.implicitly_wait(30)
    driver.maximize_window()

    driver.get("http://www.facebook.com")

    info = "Enter your e-mail"
    print(info)
    speaker.speak(info)
    user_name = input("email : ")

    info = "Enter your password"
    print(info)
    speaker.speak(info)
    pwd = getpass.getpass("password : "******"Facebook" in driver.title

    elem = driver.find_element_by_id("email")
    elem.send_keys(user_name)

    elem = driver.find_element_by_id("pass")
    elem.send_keys(pwd)

    elem.send_keys(Keys.RETURN)

    info = "Your facebook account is opening."
    print(info)
    speaker.speak(info)

    input("HALT")
    # close the browser window
    driver.close()
    return
コード例 #10
0
ファイル: google.py プロジェクト: sshacker/JARVIS
def google(query):
    """
        TASK TO GOOGLE SEARCH 
    """
    # create a new Firefox session
    driver = webdriver.Chrome()
    driver.implicitly_wait(30)
    driver.maximize_window()
    
    # Navigate to the application home page
    driver.get("http://www.google.com")
    
    # get the search textbox
    search_field = driver.find_element_by_name("q")
    search_field.clear()
    
    to_search = query.split("SEARCH")[1].strip()
    
    #user input query
    #user_search_query=input("enter search query :")

    # enter search keyword and submit
    search_field.send_keys(to_search)
    search_field.submit()
    
    # get the list of elements which are displayed after the search
    # currently on result page using find_elements_by_class_name method
    lists= driver.find_elements_by_class_name("ellip")

    # get the number of elements found
    print ("Found " + str(len(lists)) + " searches:")

    # iterate through each element and print the text that is
    # name of the search

    i=0
    for listitem in lists:
        item = listitem.get_attribute("innerHTML")
        print (str(i+1)+".",item)
        speaker.speak(item)
        i=i+1
        if(i>=5):
            print(".... and many more search results")
            break

            
    info = "which item number would you like to open"
    print(info)
    speaker.speak(info)
    
    i=int(input("enter item number : "))
    lists[i-1].click()
    
    info="start opening..."
    print(info)
    speaker.speak(info)
    
    input("HALT")
    # close the browser window
    driver.quit()
 
    return
コード例 #11
0
ファイル: youtube.py プロジェクト: sshacker/JARVIS
def youtube(query):
    """
		TASK TO YOUTUBE SEARCH
	"""
    # create a new Chrome session
    driver = webdriver.Chrome()
    driver.maximize_window()

    # Navigate to the application home page
    driver.get("http://www.youtube.com")

    # get the search textbox
    search_field = driver.find_element_by_name("search_query")
    search_field.clear()

    #user input query
    #user_search_query=input("enter search query :")

    to_search = ""
    if "PLAY" in query:
        to_search = query.split("PLAY")[1].strip()
    elif "SEARCH" in query:
        to_search = query.split("SEARCH")[1].strip()

    # enter search keyword and submit
    search_field.send_keys(to_search)
    search_field.submit()

    # get the list of elements which are displayed after the search
    # currently on result page using find_elements_by_class_name method
    lists = driver.find_elements_by_id("video-title")

    # get the number of elements found
    print("Found " + str(len(lists)) + " searches:")

    current_page_url = driver.current_url
    print(current_page_url)

    i = 0
    for listitem in lists:
        item = listitem.get_attribute("innerHTML")
        print(str(i + 1) + ".", item)
        speaker.speak(item)
        i = i + 1
        if (i >= 3):
            print("... and many more search results")
            break

    info = "which item number would you like to play"
    print(info)
    speaker.speak(info)

    i = int(input("enter item number : "))
    lists[i - 1].click()

    info = "start playing..."
    print(info)
    speaker.speak(info)

    #player
    q = "'PLAY"
    while q.upper() != "STOP":
        q = input("enter : ")
        if q.upper() == "PLAY" or q.upper() == "PAUSE":
            p = driver.find_elements_by_xpath('//*[@id="player"]')
            p[0].click()

    # close the browser window
    driver.quit()

    return