Ejemplo n.º 1
0
def create_event():
    service = calendar_service()
    respond("summary of the event")
    summary = listen()
    year = datetime.now().year
    month = datetime.now().month
    date = get_event_date()
    hour, minute = get_event_time()
    event_duration = get_event_duration()
    start_day = datetime(year, month, date, hour, minute)
    start = start_day.isoformat()
    end = (start_day + timedelta(hours = event_duration)).isoformat()

    event = {
        'summary': summary,
        'start': {
            'dateTime': start,
            'timeZone': 'Asia/Kolkata',
        },
        'end': {
            'dateTime': end,
            'timeZone': 'Asia/Kolkata',
        },
        'attendees' : [
            {'email' : '*****@*****.**'}
        ]
    }
    event = service.events().insert(calendarId='primary', body=event).execute()
    respond("event created successfully")
    return
Ejemplo n.º 2
0
def get_event_date():
    try:
        respond("event Date")
        date_ = (listen()).split()
        date = int(date_[1][0:2])
        return date
    except:
        respond("Pardon me,please say that again")
        get_event_date()
Ejemplo n.º 3
0
def get_event_duration():
    try:
        respond("event duration")
        event_duration = listen().split()
        event_duration = int(event_duration[0])
        return event_duration
    except:
        respond("Pardon me, please say that again")
        get_event_duration()
def access():
    respond("Are you confirm in access control transfer!")
    data = listen()
    if "confirm" in data or "yes" in data or "yeah" in data:
        respond("could you please say the name of  the person of whom you are going to give access")
        name = listen()
        respond("okay")
        respond("new visual confirmation required!")
        New_access(name)
        respond("access control transferred successfully!")
        return
    else:
        respond("are you sure in cancelling access control transfer!")
        data = listen()
        if data == "yes":
            return
        else:
            access()
Ejemplo n.º 5
0
def get_event_time():
    try:
        respond("event time")
        event_time = listen().split()
        hour = int(event_time[0][0:2])
        minute = int(event_time[0][-2:])
        if event_time[1][0] == "p":
            hour = hour + 12 
        return hour, minute
    except:
        respond("Pardon me,please say that again")
        get_event_time()
def execute_commands():
    try:
        respond("okay sir!")
        respond("please give me the list of instruction to execute")
        a=[]
        while True:
            data = listen()
            if "that's it" in data:
                break
            else:
                a.append(data)
                respond("okay")
        for instruct in a:
            speech="your instruction {} is going to execute sir!".format(instruct)
            respond(speech)
            digital_assistant(instruct)       
    except:
        respond("sorry sir, there is an error occurred. Could you plese repeat commands to do!")
    return
Ejemplo n.º 7
0
#The above copyright notice and this permission notice shall be included in all
#copies or substantial portions of the Software.

#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#SOFTWARE.

import os
import time
from RespondListen import respond, listen
from digital_assistant import init_check, intiate_jarvis, digital_assistant, contain
if __name__ == "__main__":
    if init_check():
        intiate_jarvis()
        while True:
            respond("Please tell me how can i help you?")
            data = listen().lower()
            if data == 0:
                continue
            if contain(data, ["turn off", "stop", "exit", "bye"]):
                os.system("taskkill /f /im Rainmeter.exe")
                respond("I am going to sleep sir, Have a nice day!")
                break
            digital_assistant(data)
            time.sleep(2)
def digital_assistant(data):
    try:   
        if data == "jarvis":
            respond("yes sir! I am at your service")
            return
            
        elif "how are you" in data: 
            respond("I am well")
            return

        elif contain(data,["define yourself","what can you do","who are you"]):
            respond("I am viswanadh's personal assistant, I am programmed to do minor tasks like system monitoring, profiling,"
            "predict time, take a photo, predict weather,"
            " opening applications like youtube, google chrome ,gmail etcetre, show the top headline news and you can ask me computational or geographical questions too!")
            return
        
        elif contain(data,["who made you","who created you"]):
            respond("I was built by viswa")
            return

        elif "shutdown" in data:
            respond("Are you sure! you want to shutdown your computer")
            data = listen()
            if data == "yes":
                respond("system is going to shutdown...")
                os.system("taskkill /f /im Rainmeter.exe")
                os.system("shutdown /s /t 1")
                return
        
        elif "restart" in data:
            respond("want to restart your computer")
            data=listen()
            if data=="yes":
                os.system("shutdown /r /t 1")
                return

        elif "music" in data:
            respond("Here you go with music")
            music_dir = "C:\\Users\\VISWANADH\\Music"
            song = random.choice(os.listdir(music_dir))
            os.startfile(os.path.join(music_dir,song))
            time.sleep(5)
            return

        elif "movie" in data:
            os.system("D:\\movies\\Ala_Vaikunthapurramloo.mkv")
            time.sleep(5)
            return
        
        elif "notepad" in data:
            os.system("notepad")
            return

        elif contain(data,['select all','cut','copy','paste','history','download','undo','redo','save','enter','search','find']):
            Ctrl_Keys(data)
            return

        elif "open" in data:
            if "tab" in data:
                Tab_Opt(data)
                time.sleep(10)
                respond("what do you wanna search sir!")
                data = listen()
                if "search" in data:
                    keys.Paste()
                else:
                    pyautogui.typewrite(data)
                keys.Enter()
            elif "window" in data:
                Win_Opt(data)
            elif "chrome" in data:
                time.sleep(3)
                webbrowser.open("http://www.google.com/")
                time.sleep(10)
                respond("what do you wanna search sir!")
                data = listen()
                if "search" in data:
                    keys.Paste()
                else:
                    pyautogui.typewrite(data)
                keys.Enter()
            else:
                data = data.split(" ")
                query = data[1]
                for j in search(query, tld='com', lang='en', num=1, start=0, stop=1, pause=2.0):
                    url=j
                webbrowser.get('chrome').open_new(url)
                respond(data[1] + " is open now")
                time.sleep(7)
            return

        elif "news" in data:
            query = "news"
            url="https://timesofindia.indiatimes.com/home/headlines"
            webbrowser.get('chrome').open_new(url)
            respond("Here are some headlines from the Times of India,Happy reading")
            time.sleep(5)
            return
                
        elif "weather" in data:
            data=data.split(" ")
            api_key = "###############################"
            base_url = "https://api.openweathermap.org/data/2.5/weather?"
            if "in" not in data:
                city_name = "kurupam"
            else:
                city_name = data[-1]
            complete_url = base_url + "appid=" + api_key + "&q=" + city_name
            response = requests.get(complete_url)
            x = response.json()
            if x["cod"] != "404":
                y = x["main"]
                current_temperature = y["temp"]
                current_humidiy = y["humidity"]
                z = x["weather"]
                weather_description = z[0]["description"]
                respond(" Temperature in kelvin unit at " + city_name + " is " +
                      str(current_temperature) +
                      "\n humidity in percentage is " +
                      str(current_humidiy) +
                      "\n description  " +
                      str(weather_description))
                return
            else:
                respond(city_name + " weather details not found")
                return
        
        elif "something" in data:
            respond("Searching...")
            data=data.split(" ")
            data = data[3:]
            Req_data = ""
            for word in data:
                Req_data = Req_data + " " + word
            data =  "According to wikipedia " + wikipedia.summary(Req_data, sentences=4) 
            respond(data)
            return

        elif contain(data,["take a photo","capture the photo"]):
            ec.capture(0,False,"img.jpg")
            respond("photo captured successfully")
            return

        elif contain(data,["video","record the video"]):
            ec.auto_vidcapture(0,False,"video.mkv",10)
            respond("video recorded successfully")
            return

        elif "access" in data:
            access()
            return
        
        elif "where is" in data:
            data = data.split(" ")
            name = data[-1]
            url = "https://www.google.com/maps/place/"+name
            webbrowser.get('chrome').open_new(url)
            time.sleep(5)
            return

        elif "write a note" in data:
            respond("What should i write, sir!")
            data = listen()
            file = open('note.txt', 'a')
            file.write("\n"+ctime()+"\n")
            file.write(data)
            respond("noted successfully")
            return
        
        elif "execute" in data:
            execute_commands()
            return

        elif contain(data,["upcoming events","scheduled events","events"]):
            calendar_events()
            return

        elif contain(data,["game","play"]):
            try:
                tic_tac_toe()
                return
            except:
                return

        elif "create event" in data:
            create_event()
            return
            
        elif contain(data,["speed test","internet speed"]):
            try:
                respond("sure! wait a second to measure")
                st = speedtest.Speedtest()
                server_names = []
                st.get_servers(server_names)
                ping = st.results.ping
                downlink_Mbps = round(st.download() / 1000000, 2)
                uplink_Mbps = round(st.upload() / 1000000, 2)
                respond('ping {} ms'.format(ping))
                respond("The uplink is {} Mbps".format(uplink_Mbps))
                respond("The downlink is {}Mbps".format(downlink_Mbps))
                return
            except:
                respond ("I couldn't run a speedtest")     
                return              
        
        elif contain(data,["internet connection","connection"]):
            if internet_availability():
                respond("Internet Connection is okay!")
            return

        elif "wait" in data:
            respond("okay sir")
            time.sleep(10)
            return
        
        elif "screenshot" in data:
            Screenshot = pyautogui.screenshot()
            dir = "C:\\Users\VISWANADH\Pictures\Screenshots"
            length = len(os.listdir(dir))
            Screenshot_name = "Screenshot({}).png".format(length)
            path = os.path.join(dir,Screenshot_name)
            Screenshot.save(path)
            respond("Screenshot saved Successfully!")
            return

        elif "tab" in data:
            Tab_Opt(data)
            return
        
        elif "window" in data:
            Win_Opt(data)
            return
        
        elif contain(data,['battery', 'cpu', 'memory', 'brightness']):
            System_specs(data)
            return

        elif "time" in data:      
            respond(ctime())
            return

        else:
            respond("I can search the web for you,Do you want to continue?")
            opinion=listen()
            if opinion=="yes":
                url="https://www.google.com/search?q =" + '+'.join(data.split())
                webbrowser.get('chrome').open_new(url)
                time.sleep(5)
                return
            else:
                return
    except:
        respond("I don't understand, I can search the web for you,Do you want to continue?")
        opinion=listen()
        if opinion=="yes":
            url="https://www.google.com/search?q =" + '+'.join(data.split())
            webbrowser.get('chrome').open_new(url)
            time.sleep(5)
            return
        else:
            return
def digital_assistant(data):
    try:
        if "how are you" in data: 
            respond("I am well")
            return
            
        elif "time" in data:      
            respond(ctime())
            return

        elif "who are you" in data or "what can you do" in data or "define yourself" in data:
            respond("I am viswanadh's personal assistant, I am programmed to do minor tasks like system monitoring, profiling,"
            "predict time, take a photo, predict weather,"
            " opening applications like youtube, google chrome ,gmail etcetre, show the top headline news and you can ask me computational or geographical questions too!")
            return

        elif "who made you" in data or "who created you" in data:
            respond("I was built by viswa")
            return

        elif "shutdown" in data:
            respond("Are you sure! you want to shutdown your computer")
            data = listen()
            if data == "yes":
                respond("system is going to shutdown...")
                os.system("taskkill /f /im Rainmeter.exe")
                os.system("shutdown /s /t 1")
                return
        
        elif "restart" in data:
            respond("want to restart your computer")
            data=listen()
            if data=="yes":
                os.system("shutdown /r /t 1")
                return
        
        elif "battery" in data:
            battery=psutil.sensors_battery()
            respond("Your system is at " + str(battery.percent) + " percent")
            return

        elif "cpu" in data:
            respond("CPU is at "+ str(psutil.cpu_percent()))
            return

        elif "music" in data:
            respond("Here you go with music")
            music_dir = "C:\\Users\\VISWANADH\\Music"
            song = random.choice(os.listdir(music_dir))
            os.startfile(os.path.join(music_dir,song))
            time.sleep(5)
            return

        elif "movie" in data:
            os.system("D:\\movies\\Ala_Vaikunthapurramloo.mkv")
            time.sleep(5)
            return
        
        elif "notepad" in data:
            os.system("notepad")
            return

        elif "open" in data:
            data = data.split(" ")
            query = data[1]
            for j in search(query, tld='com', lang='en', num=1, start=0, stop=1, pause=2.0):
                url=j
            webbrowser.get('chrome').open_new(url)
            respond(data[1] + " is open now")
            time.sleep(7)
            return

        elif "news" in data:
            query = "news"
            url="https://timesofindia.indiatimes.com/home/headlines"
            webbrowser.get('chrome').open_new(url)
            respond("Here are some headlines from the Times of India,Happy reading")
            time.sleep(5)
            return
                
        elif "weather" in data:
            data=data.split(" ")
	    #create key: https://home.openweathermap.org/users/sign_in
            api_key = ####################
            base_url = "https://api.openweathermap.org/data/2.5/weather?"
            if "in" not in data:
                city_name = "kurupam"
            else:
                city_name = data[-1]
            complete_url = base_url + "appid=" + api_key + "&q=" + city_name
            response = requests.get(complete_url)
            x = response.json()
            if x["cod"] != "404":
                y = x["main"]
                current_temperature = y["temp"]
                current_humidiy = y["humidity"]
                z = x["weather"]
                weather_description = z[0]["description"]
                respond(" Temperature in kelvin unit at " + city_name + " is " +
                      str(current_temperature) +
                      "\n humidity in percentage is " +
                      str(current_humidiy) +
                      "\n description  " +
                      str(weather_description))
                return
            else:
                respond(city_name + " weather details not found")
                return
        
        elif "something" in data:
            respond("Searching...")
            data=data[22:]
            data =  "According to wikipedia " + wikipedia.summary(data, sentences=4) 
            respond(data)
            return

        elif "capture the photo" in data or "take a photo" in data:
            ec.capture(0,False,"img.jpg")
            respond("photo captured successfully")
            return

        elif "video" in data or "capture the video" in data:
            ec.auto_vidcapture(0,False,"video.mkv",10)
            respond("video recorded successfully")
            return

        elif "access" in data:
            access()
            return
        
        elif "where is" in data:
            data = data.split(" ")
            name = data[-1]
            url = "https://www.google.com/maps/place/"+name
            webbrowser.get('chrome').open_new(url)
            time.sleep(5)
            return

        elif "write a note" in data:
            respond("What should i write, sir!")
            data = listen()
            file = open('note.txt', 'w')
            file.write(data)
            respond("noted successfully")
            return
        
        elif "execute" in data:
            execute_commands()
            return

        elif "upcoming events" in data or "scheduled events" in data or "events" in data:
            events = calendar_events()
            return

        elif "game" in data or "play" in data:
            try:
                tic_tac_toe()
                return
            except:
                return

        elif "create event" in data:
            create_event()
            return
            
        elif "speed test" in data:
            try:
                respond("sure! wait a second to measure")
                st = speedtest.Speedtest()
                server_names = []
                st.get_servers(server_names)
                ping = st.results.ping
                downlink_Mbps = round(st.download() / 1000000, 2)
                uplink_Mbps = round(st.upload() / 1000000, 2)
                respond('ping {} ms'.format(ping))
                respond("The uplink is {} Mbps".format(uplink_Mbps))
                respond("The downlink is {}Mbps".format(downlink_Mbps))
                return
            except:
                respond ("I couldn't run a speedtest")     
                return              
        
        elif "memory" in data:
            process_id = os.getpid()
            py = psutil.Process(process_id)
            memory_use = round(py.memory_info()[0]/2. **30, 2)
            respond("I use {} Gb of memory".format(memory_use))
            return
        
        elif "internet connection" in data or "internet" in data:
            if internet_availability():
                respond("Internet Connection is okay!")
            return
       elif 'email to' in data:
            try:
                respond("Sir, give me your message")
                print('Give message.......')
                content = takeCommand()
                to = "receiver email address"
                sendEmail(to, content)
                print('Sending mail........')
                respond("Email has been sent!")
            except Exception as e:
                print(e)
                respond("Sorry master . I am not able to send this email")
       elif 'email to' in data:
            try:
                respond("Sir, give me your message")
                print('Give message.......')
                content = takeCommand()
                to = "receiver email address"
                sendEmail(to, content)
                print('Sending mail........')
                respond("Email has been sent!")
            except Exception as e:
                print(e)
                respond("Sorry master . I am not able to send this email")

        else:
            respond("I can search the web for you,Do you want to continue?")
            opinion=listen()
            if opinion=="yes":
                url="https://www.google.com/search?q =" + '+'.join(data.split())
                webbrowser.get('chrome').open_new(url)
                time.sleep(5)
                return
            else:
                return
    except:
        respond("I don't understand, I can search the web for you,Do you want to continue?")
        opinion=listen()
        if opinion=="yes":
            url="https://www.google.com/search?q =" + '+'.join(data.split())
            webbrowser.get('chrome').open_new(url)
            time.sleep(5)
            return