Exemplo n.º 1
0
def authenticate_google():
    """Shows basic usage of the Google Calendar API.
    Prints the start and name of the next 10 events on the user's calendar.
    """
    try:
        creds = None

        if os.path.exists('token.pickle'):
            with open('token.pickle', 'rb') as token:
                creds = pickle.load(token)

        if not creds or not creds.valid:
            if creds and creds.expired and creds.refresh_token:
                creds.refresh(Request())
            else:
                flow = InstalledAppFlow.from_client_secrets_file(
                    'credentials.json', SCOPES)
                creds = flow.run_local_server(port=0)

            with open('token.pickle', 'wb') as token:
                pickle.dump(creds, token)

        service = build('calendar', 'v3', credentials=creds)

        return service

    except Exception as e:
        engine.speak("sorry master" + str(e))
def youtube_search(text):
    try:
        IPaddress = socket.gethostbyname(socket.gethostname())
        if IPaddress == "127.0.0.1":
            engine.speak("there is something wrong while connecting master")
        else:
            url = 'https://www.youtube.com/results?search_query='
            search_url = url + text
            engine.speak("opening results master")
            webbrowser.get('google-chrome').open_new_tab(search_url)
    except:
        pass
def typein():
    try:
        while 1:
            text = Audio.get_audio()
            k=Controller()

            if text in strlists.VOICETYPING_KEYPRESSES_STR:
                for phrase in strlists.VOICETYPING_KEYPRESSES_STR:
                    
                    if "select all" in text:
                        pyautogui.hotkey('ctrl','a')
                    elif "undo" in text:
                        pyautogui.hotkey('ctrl','z')
                    elif "redo" in text:
                        pyautogui.hotkey('ctrl','y')
                    elif "copy" in text:
                        pyautogui.hotkey('ctrl','c')
                    elif "paste" in text:
                        pyautogui.hotkey('ctrl','v')
                    elif "italic" in text:
                        pyautogui.hotkey('ctrl','i')
                    elif "cut" in text:
                        pyautogui.hotkey('ctrl','x')
                        pass

                    elif phrase in text:
                        pyautogui.press(phrase)
                    
            
            
            elif 'switch off voice typing' in text:
                engine.speak("getting out of voice typing master")
                time.sleep(2)
                break

            else:
                k.type(text)
                continue


                        
                        
    
    
    except:
        engine.speak("something went wrong master!!")

        
def wikipedia_search():
    try:
        engine.speak(
            "what to search in wikipedia master?please tell me again clearly master"
        )
        search_string = Audio.get_audio()
        engine.speak("searching master")
        print(wikipedia.summary(search_string, sentences=2))
        engine.speak(wikipedia.summary(search_string, sentences=2))
    except:
        engine.speak("sorry master no results found!")
def fetch_google_news():
    try:

        news_url = "https://news.google.com/news/rss"
        Client = urlopen(news_url)
        xml_page = Client.read()
        Client.close()

        soup_page = soup(xml_page, "xml")
        news_list = soup_page.findAll("item")
        # Print news title, url and publish date
        for news in news_list:
            print(news.title.text)
            engine.speak(news.title.text)

    except:

        engine.speak(
            'something went wrong master,it seems our internet connection felt to be failed master!'
        )
def get_events(day, service):
    try:
        # Call the Calendar API
        date = datetime.datetime.combine(day, datetime.datetime.min.time())
        end_date = datetime.datetime.combine(day, datetime.datetime.max.time())
        utc = pytz.UTC
        date = date.astimezone(utc)
        end_date = end_date.astimezone(utc)
        events_result = service.events().list(calendarId='primary',
                                              timeMin=date.isoformat(),
                                              timeMax=end_date.isoformat(),
                                              singleEvents=True,
                                              orderBy='startTime').execute()
        events = events_result.get('items', [])
        if not events:
            engine.speak("No upcoming events found master ")
        else:
            engine.speak("you have " + len(events) + "events on this day.")

            for event in events:
                start = event['start'].get('dateTime',
                                           event['start'].get('date'))
                print(start, event['summary'])
                start_time = str(start.split("T")[1].split("-")[0])

                if int(start_time.split(":")[0]) < 12:
                    start_time = start_time + "am"

                else:
                    start_time = str(int(start_time.split(":")[0]) -
                                     12) + start_time.split(":")[1]
                    start_time = start_time + "pm"
                engine.speak(event["summary"] + "at" + start_time)
    except:
        pass
def get_weather(text):
    api_key = "707a14b1964cdcfc1aeb7b471d5c3322"
    base_url = "http://api.openweathermap.org/data/2.5/weather?"
    complete_url = base_url + "appid=" + api_key + "&q=" + text
    response = requests.get(complete_url)
    x = response.json()
    try:
        if x["cod"] != "404":
            y = x["main"]
            current_temperature = y["temp"]
            current_pressure = y["pressure"]
            current_humidiy = y["humidity"]
            z = x["weather"]
            weather_description = z[0]["description"]
            print(" Temperature (in kelvin unit) = " +
                  str(current_temperature) +
                  "\n atmospheric pressure (in hPa unit) = " +
                  str(current_pressure) + "\n humidity (in percentage) = " +
                  str(current_humidiy) + "\n description = " +
                  str(weather_description))
            engine.speak(" Temperature (in kelvin unit) = " +
                         str(current_temperature) +
                         "\n atmospheric pressure (in hPa unit) = " +
                         str(current_pressure) +
                         "\n humidity (in percentage) = " +
                         str(current_humidiy) + "\n description = " +
                         str(weather_description))
        else:
            engine.speak("sorry master I am unable to find the city master")

    except:
        engine.speak("sorry master something happened while checking weather")
        pass
Exemplo n.º 8
0
def speak(audio):
    engine.speak(audio)