コード例 #1
0
def run_alexa():
    command = take_command()
    print(command)
    if 'play' in command:
        song = command.replace('play', '')
        talk('playing' + song)
        pywhatkit.playonyt(song)
    elif 'time' in command:
        time = datetime.datetime.now().strftime('%H:%M')
        talk('Current time is ' + time)
    elif 'google' in command:
        webbrowser.open('www.google.com')
    elif 'facebook' in command:
        webbrowser.open('www.facebook.com')
    elif 'gmail' in command:
        webbrowser.open('www.gmail.com')
    elif 'twitter' in command:
        webbrowser.open('www.twitter.com')
    elif 'weather' in command:
        wf.forecast(place="Tetovo",
                    time="14:15:00",
                    date="2021-01-17",
                    forecast="daily")
    elif 'search for' or 'find me' or 'who is' in command:
        query = command.replace('search for', '')
        info = wikipedia.summary(query, 2)
        print(info)
        talk(info)
    else:
        talk("Please say the command again.")
コード例 #2
0
def weather():
    place = e1.get()
    now = datetime.datetime.now()
    date = now.strftime("%y%y-%m-%d")
    time = (now.strftime("%H:%M:%S"))
    fore = (wf.forecast(place=place, time=time, date=date, forecast="daily"))
    print(fore)
    speak(fore)
    e1.pack_forget()
    b.pack_forget()
コード例 #3
0
def voice_control(filename):
    file = filename
    f = open(file, 'r')
    command = f.read()
    f.close()  # close file aviod IOException
    print command

    if command.find('开') != -1 and command.find('灯') != -1:
        #print '开灯'
        LED_light(True)
        os.system('mplayer %s' % 'music/lightOn.mp3')
    elif command.find('关') != -1 and command.find('灯') != -1:
        #print '关灯'
        LED_light(False)
        os.system('mplayer %s' % 'music/lightOff.mp3')
    elif command.find('天') != -1 and command.find('气') != -1:
        weather.forecast()
    elif command.find('放') != -1 and command.find('音') != -1 and command.find(
            '乐') != -1:
        try:
            os.system('mplayer %s' % 'music/小跳蛙.mp3')
        except KeyboardInterrupt:
            pass
    elif command.find('自') != -1 and command.find('我') != -1 and command.find(
            '介') != -1 and command.find('绍') != -1:
        tts.tts('我是小博,我能说会道,是机器人界的网红段子手,哈哈哈.')
        os.system('mplayer %s' % 'synthesis.mp3')
    elif command.find('编') != -1 and command.find('程') != -1 and command.find(
            '语') != -1 and command.find('言') != -1:
        tts.tts('我不喜欢编程')
        os.system('mplayer %s' % 'synthesis.mp3')
    elif command.find('去') != -1 and command.find('打') != -1 and command.find(
            '球') != -1:
        tts.tts('打个毛球啊,我要好好学习,走上人生巅峰。')
        os.system('mplayer %s' % 'synthesis.mp3')
    elif command.find('几') != -1 and command.find('岁') != -1:
        tts.tts('哼,我不想告诉你。')
        os.system('mplayer %s' % 'synthesis.mp3')
    else:
        os.system('mplayer %s' % 'synthesis.mp3')
コード例 #4
0
ファイル: jarvis.py プロジェクト: yashgorey/Jarvis.py
            print(songs)
            os.startfile(os.path.join(music_dir, songs[0]))

        elif 'the time' in query:
            strTime = datetime.datetime.now().strftime("%H:%M:%S")
            speak(f"Ma'am , the time is {strTime}")

        elif "camera" in query or "take a photo" in query:
            ec.capture(0, "Jarvis Camera ", "img.jpg")

        elif 'weather' in query:
            #x=input("Enter the place-")
            #y=input("Enter the Time(24hr)-")
            #z=input("Enter the date(Y-m-d)-")
            wf.forecast(place='delhi',
                        time=datetime.datetime.now(),
                        date=datetime.now().strftime('%Y-%m-%d'),
                        forecast="daily")
            speak('okay')

        elif 'open code' in query:
            codePath = "C:\\Users\\user\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Visual Studio Code"
            os.startfile(codePath)

        elif 'exit' in query:
            speak("Thanks for giving me your time")
            exit()

        elif 'email to priyanka' in query:
            try:
                speak("What should I say?")
                content = takeCommand()
コード例 #5
0
import weather_forecast as wf

wf.forecast(place="Bern", time="00:00:00", date="2020-06-10", forecast="daily")
コード例 #6
0
import weather_forecast as wf

wf.forecast(place="Bern", time="00:00:00", date="2021-01-20", forecast="daily")
コード例 #7
0
ファイル: shambhavi.py プロジェクト: codewithpom/Shambhavi-AI
    elif 'make contact' in query:
        speak('Name of the contact')
        name = takeCommand()
        speak('What is the e- MAIL ADDRESS')
        email = input('What is the E mail address')
        speak('What is the phone number with country code')
        number = input('What is the phone number')
        file_name = name + '.txt'
        file_location = 'contacts/' + file_name
        file = open(file_location, 'a')
        file.write(number + '\n')
        file.write(email)

    elif 'weather' in query or 'weather forecast' in query:
        whether = wf.forecast(place="Muzaffarpur")
        place = whether['place']
        time = whether['time']
        dat = whether['date']
        day = whether['day']
        day_temperature = day['temperature']
        day_precipitate = day['precipitate']
        day_uv_description = day['uv_description']
        day_windspeed = day['wind_speed']
        day_humidity = day['humidity']
        day_phrase = day['phrases']
        day_narrative = day['narrative']
        print('Location:' + place)
        speak('Location is ' + place)
        print('Time:' + time)
        speak('The time is ' + time)
コード例 #8
0
import wikipedia
import weather_forecast as wf
from playsound import playsound
import datetime
import time
import cv2
import webbrowser

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')

engine.setProperty('voice', voices[1].id)

clock = time.ctime()
aweatherfor = wf.forecast(place="ahmedabad",
                          time="23:15:00",
                          date="2021-01-09",
                          forecast="daily")


def speak(audio):
    engine.say(audio)
    engine.runAndWait()


def wishMe():
    hour = int(datetime.datetime.now().hour)
    if hour >= 0 and hour < 12:
        speak("Good Morning!")

    elif hour >= 12 and hour < 18:
        speak("Good Afternoon!")
コード例 #9
0
from datetime import date, datetime
today = date.today()
now = datetime.now()
d = now.strftime("%Y-%m-%d")
t = now.strftime("%H:%M:%S")
print("Today's date:", d, 'now=', t)
import weather_forecast as wf
wf.forecast(place='Hayward', time=t, date=d, forecast='daily')
コード例 #10
0
import weather_forecast as wf
from datetime import datetime, date

location = input('Where do you live? ')
#location = 'Grand Rapids'
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
today = date.today()
today2 = str(
    today
)  #API requires a string not a date so convert the date to a string here then call it

wf.forecast(place=location, time=current_time, date=today2, forecast="daily")
コード例 #11
0
ファイル: main.py プロジェクト: kleong12/Auto-Bot-BEI
def game():

    for i in range(1000):

        request = input('Auto-Bot at your service. Please state your request. ')

        if request == 'google':
            query = input('Search: ')
            print(search(query, num_results = 3))


        elif request == 'stocks':
            ticker = input('Ticker Symbol: ')
            realticker = yf.Ticker(ticker)
            print(realticker.history(period= '1m'))

        elif request == 'weather':
            place = input('City: ')
            weather = weather_forecast.forecast(place=place, time=current_time, date=d1)
            


        elif request == 'email':
            to = input('Email address: ')
            content = input('What do you want to say? ')






            address = '*****@*****.**'
            password = '******'
            server = 'imap.gmail.com'



            s = bot.SMTP(host= 'smtp.gmail.com', port= 587)
            s.starttls()
            s.login(address, password)
            s.ehlo()


            s.sendmail(address, to ,content)
            {}
        elif request == 'song':
            song = input('Song name: ')
            results = YoutubeSearch(song, max_results=1).to_dict()
            dict = results[0].values()
            newdict = list(dict)

            url = newdict[7]



            print(f'https://www.youtube.com{url}')

        elif request == 'news':

            news = input('Search news: ')
            gn = GoogleNews()
            top = gn.search(news)
            newnews = gn.results()

            dict = list(newnews[0].values())
            dicttwo = list(newnews[1].values())
            dictthree = list(newnews[2].values())
            dictfour = list(newnews[3].values())
            dictfive = list(newnews[4].values())



            title1 = dict[0]
            title2 = dicttwo[0]
            title3 = dictthree[0]
            title4 = dictfour[0]
            title5 = dictfive[0]

            src1 = dict[1]
            src2 = dicttwo[1]
            src3 = dictthree[1]
            src4 = dictfour[1]
            src5 = dictfive[1]

            cap1 = dict[4]
            cap2 = dicttwo[4]
            cap3 = dictthree[4]
            cap4 = dictfour[4]
            cap5 = dictfive[4]

            url1 = dict[5]
            url2 = dicttwo[5]
            url3 = dictthree[5]
            url4 = dictfour[5]
            url5 = dictfive[5]

            print(f'Title: {title1}')
            print(f'Source: {src1}')
            print(f'Caption: {cap1}')
            print(f'Url: {url1}')

            print(f'Title: {title2}')
            print(f'Source: {src2}')
            print(f'Caption: {cap2}')
            print(f'Url: {url2}')

            print(f'Title: {title3}')
            print(f'Source: {src3}')
            print(f'Caption: {cap3}')
            print(f'Url: {url3}')

            print(f'Title: {title4}')
            print(f'Source: {src4}')
            print(f'Caption: {cap4}')
            print(f'Url: {url4}')

            print(f'Title: {title5}')
            print(f'Source: {src5}')
            print(f'Caption: {cap5}')
            print(f'Url: {url5}')








        elif request == 'math':

            def add(x, y):
                return x + y

            # This function subtracts two numbers
            def subtract(x, y):
                return x - y

            # This function multiplies two numbers
            def multiply(x, y):
                return x * y

            # This function divides two numbers
            def divide(x, y):
                return x / y



            while True:
                # Take input from the user
                choice = input("Enter choice( + / - / * / / ): ")

                # Check if choice is one of the four options
                if choice in ('+', '-', '*', '/'):
                    num1 = float(input("Enter first number: "))
                    num2 = float(input("Enter second number: "))

                    if choice == '+':
                        print(num1, "+", num2, "=", add(num1, num2))

                    elif choice == '-':
                        print(num1, "-", num2, "=", subtract(num1, num2))

                    elif choice == '*':
                        print(num1, "*", num2, "=", multiply(num1, num2))

                    elif choice == '/':
                        print(num1, "/", num2, "=", divide(num1, num2))
                    break
                else:
                    print("Invalid Input")

        elif request == 'game':

            type = input('Which game? Press 1 for tic-tac-toe, press 2 for rock-paper-scissors ')

            if type == '1':
                unused_keys = ['1', '2', '3', '4', '5', '6', '7', '8', '9']
                theBoard = {'7': ' ', '8': ' ', '9': ' ',
                            '4': ' ', '5': ' ', '6': ' ',
                            '1': ' ', '2': ' ', '3': ' '}

                board_keys = []

                for key in theBoard:
                    board_keys.append(key)

                ''' We will have to print the updated board after every move in the game and 
                    thus we will make a function in which we'll define the printBoard function
                    so that we can easily print the board everytime by calling this function. '''

                def printBoard(board):
                    print(board['7'] + '|' + board['8'] + '|' + board['9'])
                    print('-+-+-')
                    print(board['4'] + '|' + board['5'] + '|' + board['6'])
                    print('-+-+-')
                    print(board['1'] + '|' + board['2'] + '|' + board['3'])

                # Now we'll write the main function which has all the gameplay functionality.
                def tictactoe():

                    turn = 'X'
                    count = 0

                    for i in range(10):
                        printBoard(theBoard)
                        print("It's your turn," + turn + ".Move to which place?")

                        if turn == 'O':
                            choice = random.randint(1,9)
                            choice = unused_keys[choice]



                            if theBoard[f'{choice}'] == ' ':
                                theBoard[choice] = turn
                                unused_keys.remove(choice)
                                count += 1






                        elif turn == 'X':
                            move = input()

                            if theBoard[move] == ' ':
                                theBoard[move] = turn
                                unused_keys.remove(move)
                                count += 1
                            else:
                                print("That place is already filled.\nMove to which place?")
                                continue

                        # Now we will check if player X or O has won,for every move after 5 moves.
                        if count >= 5:
                            if theBoard['7'] == theBoard['8'] == theBoard['9'] != ' ':  # across the top
                                printBoard(theBoard)
                                print("\nGame Over.\n")
                                print(" **** " + turn + " won. ****")
                                break
                            elif theBoard['4'] == theBoard['5'] == theBoard['6'] != ' ':  # across the middle
                                printBoard(theBoard)
                                print("\nGame Over.\n")
                                print(" **** " + turn + " won. ****")
                                break
                            elif theBoard['1'] == theBoard['2'] == theBoard['3'] != ' ':  # across the bottom
                                printBoard(theBoard)
                                print("\nGame Over.\n")
                                print(" **** " + turn + " won. ****")
                                break
                            elif theBoard['1'] == theBoard['4'] == theBoard['7'] != ' ':  # down the left side
                                printBoard(theBoard)
                                print("\nGame Over.\n")
                                print(" **** " + turn + " won. ****")
                                break
                            elif theBoard['2'] == theBoard['5'] == theBoard['8'] != ' ':  # down the middle
                                printBoard(theBoard)
                                print("\nGame Over.\n")
                                print(" **** " + turn + " won. ****")
                                break
                            elif theBoard['3'] == theBoard['6'] == theBoard['9'] != ' ':  # down the right side
                                printBoard(theBoard)
                                print("\nGame Over.\n")
                                print(" **** " + turn + " won. ****")
                                break
                            elif theBoard['7'] == theBoard['5'] == theBoard['3'] != ' ':  # diagonal
                                printBoard(theBoard)
                                print("\nGame Over.\n")
                                print(" **** " + turn + " won. ****")
                                break
                            elif theBoard['1'] == theBoard['5'] == theBoard['9'] != ' ':  # diagonal
                                printBoard(theBoard)
                                print("\nGame Over.\n")
                                print(" **** " + turn + " won. ****")
                                break

                                # If neither X nor O wins and the board is full, we'll declare the result as 'tie'.
                        if count == 9:
                            print("\nGame Over.\n")
                            print("It's a Tie!!")

                        # Now we have to change the player after every move.
                        if turn == 'X':
                            turn = 'O'
                        else:
                            turn = 'X'

                tictactoe()




            elif type == '2':
                print("Winning Rules of the Rock paper scissor game as follows: \n"
                  + "Rock vs paper->paper wins \n"
                  + "Rock vs scissor->Rock wins \n"
                  + "paper vs scissor->scissor wins \n")


                print("Enter choice \n 1. Rock \n 2. paper \n 3. scissor \n")


                choice = int(input("User turn: "))

                # OR is the short-circuit operator
                # if any one of the condition is true
                # then it return True value

                # looping until user enter invalid input
                while choice > 3 or choice < 1:
                    choice = int(input("enter valid input: "))

                    # initialize value of choice_name variable
                # corresponding to the choice value
                if choice == 1:
                    choice_name = 'Rock'
                elif choice == 2:
                    choice_name = 'paper'
                else:
                    choice_name = 'scissor'

                # print user choice
                print("user choice is: " + choice_name)
                print("\nNow its computer turn.......")

                # Computer chooses randomly any number
                # among 1 , 2 and 3. Using randint method
                # of random module
                comp_choice = random.randint(1, 3)

                # looping until comp_choice value
                # is equal to the choice value
                while comp_choice == choice:
                    comp_choice = random.randint(1, 3)

                    # initialize value of comp_choice_name
                # variable corresponding to the choice value
                if comp_choice == 1:
                    comp_choice_name = 'Rock'
                elif comp_choice == 2:
                    comp_choice_name = 'paper'
                else:
                    comp_choice_name = 'scissor'

                print("Computer choice is: " + comp_choice_name)

                print(choice_name + " V/s " + comp_choice_name)

                # condition for winning
                if ((choice == 1 and comp_choice == 2) or
                            (choice == 2 and comp_choice == 1)):
                    print("paper wins => ", end="")
                    result = "paper"

                elif ((choice == 1 and comp_choice == 3) or
                      (choice == 3 and comp_choice == 1)):
                    print("Rock wins =>", end="")
                    result = "Rock"
                else:
                    print("scissor wins =>", end="")
                    result = "scissor"

                # Printing either user or computer wins
                if result == choice_name:
                    print("<== User wins ==>")
                else:
                    print("<== Computer wins ==>")
コード例 #12
0
def loop():
    try:
        #Recognising the voice
        with sp.Microphone() as source:
            print('Hey... Adio here ')
            speak('Hey..adio here? how can i help u')
            voice=hear.listen(source)
            command = hear.recognize_google(voice)
            command = command.lower()
            print(command,'...')
            
        #Playing songs/videos on youtube
            if 'play' in command:
                command=command.replace('play','')
                print('playing'+command)
                pwk.playonyt(command)
            
            
        #wikipedia
            elif 'who' in command:
                command=command.replace('who is','')
                wiki=wk.summary(command,sentences=1)
                print(wiki)
                speak(wiki)
        
        
        #date and time using datetime library
            elif 'date' in command:
                date=dt.datetime.now().strftime('%d %B %Y %A')
                print(date)
                speak(date)
            
            elif 'time' in command:
                time=dt.datetime.now().strftime('%H %M %p')
                print(time)
                speak(time)
            #automate to shop on amazon   
            elif 'amazon' in command:
                command=command.replace('on amazon','')
                url='https://www.amazon.in/'
                driver=webdriver.Chrome(ChromeDriverManager().install())
                driver.get(url)
                driver.set_page_load_timeout(10)
                driver.find_element_by_xpath('//*[@id="twotabsearchtextbox"]').send_keys(command);
                search=driver.find_element_by_xpath('//*[@id="nav-search-submit-text"]/input')
                search.click()
                
            elif 'flipkart' in command:
                command=command.replace('on flipkart','')
                url='https://www.flipkart.com/'
                driver=webdriver.Chrome(ChromeDriverManager().install())
                driver.get(url)
                driver.set_page_load_timeout(10)
                driver.find_element_by_xpath('//*[@id="container"]/div/div[1]/div[1]/div[2]/div[2]/form/div/div/input').send_keys(command);
                driver.find_element_by_xpath('/html/body/div[2]/div/div/button').click()
                search=driver.find_element_by_xpath('//*[@id="container"]/div/div[1]/div[1]/div[2]/div[2]/form/div/button/svg')
                search.click()
                
                
        #google search
            elif 'search' in command:
                command=command.replace('search','')
                pwk.search(command)
            
        #jokes using pyjokes library   
            elif 'joke' in command:
                joke=pyjokes.get_jokes(language="en",)
                
                speak(joke[(random.randint(1, 5))])
                
                
                
        #Weather updates using Weather_forecast library
            elif 'weather' in command:
                
                if 'in' in command:
                    com=command.split('in',1)
                    loc=com[1].capitalize()
                    speak(wf.forecast(loc),time=dt.datetime.now().strftime('%X'),date=dt.datetime.now().strftime('%x'))
                else:
                    speak('Please repeat the question with location')
            
        #News updates using GoogleNews library     
            elif 'news' in command:
                ggn = GoogleNews('en')
                
                if 'about' in command:
                    com=command.split('about',1)
                    newz=com[1].capitalize()
                    ggn.search(newz)
                    ggn.getpage(1)
                    print(ggn.gettext())
                    speak(ggn.gettext())
                if 'on' in command:
                    com=command.split('on',1)
                    newz=com[1].capitalize()
                    ggn.search(newz)
                    ggn.getpage(1)
                    print(ggn.gettext())
                    speak(ggn.gettext())  
                
                else:
                    ggn.search('India')
                    ggn.getpage(0)
                    print(ggn.gettext())
                    speak(ggn.gettext())
                    
                        
                
                
            else:
                pwk.search(command)
                
                
                
    except:
        pass