コード例 #1
0
import pywhatkit as pwk
#(phone no. with country code , message, time: hours, minutes)
#pwk.sendwhatmsg("+919891xxxxxx", "Sent with Python", 9, 25)
#pwk.playonyt("comedy circus")
pwk.showHistory()
コード例 #2
0
ファイル: alexa.py プロジェクト: vimal0312/alexa
def run_alexa():
    command = take_command()
    print(command)
    if 'music' in command:
        song = command.replace('play song', '')
        talk('I am playing your favourite ' + song)
        # print('playing')
        print(song)
        # playing the first video that appears in yt search
        pywhatkit.playonyt(song)

    elif 'time' in command:
        now = datetime.now()
        time = now.strftime("%H:%M:%S")
        print("time:", time)
        talk("Current time is " + time)

    elif ('month' or 'year') in command:
        now = datetime.now()
        year = now.strftime("%Y")
        print("year:", year)
        talk("Current year is  " + year)
        month = now.strftime("%m")
        print("month:", month)
        talk("Current month is  " + month)

    elif 'date' in command:
        now = datetime.now()
        date_time = now.strftime("%m/%d/%Y, %H:%M:%S")
        print("date and time:", date_time)
        talk("Current date and time is " + date_time)

    # opens web.whatsapp at specified time i.e before 10 minutes and send the msg
    elif 'whatsapp' in command:
        talk("To which number do you have to whatsapp")
        talk("Please dont forget to enter 10 digits with country code")
        num = input()
        talk("Enter the message you have to send")
        msg = input()
        talk("Enter the time to send the message")
        time = int(input())
        pywhatkit.sendwhatmsg(num, msg, time, 00)
        pywhatkit.showHistory()
        pywhatkit.shutdown(3000000000)
        # pywhatkit.sendwhatmsg("+919876543210", "This is a message", 15, 00)

    # Convert text to handwritten format
    elif 'convert' in command:
        text = command.replace('convert', '')
        pywhatkit.text_to_handwriting(text, rgb=[0, 0, 0])

    # Perform google search
    elif 'search' in command:
        key = command.replace('search', '')
        pywhatkit.search("key")

    elif 'wikipedia' in command:
        person = command.replace('wikipedia', '')
        talk("How many pages do you want to read")
        num_pages = int(input())
        # talk("In which language do you want to read")
        # l = input()
        # wikipedia.set_lang(l)
        info = wikipedia.summary(person, num_pages)
        print(info)
        talk(info)

    elif 'can you work for me' in command:
        talk("sorry, I have headache. Please do your work")

    elif 'are you single' in command:
        talk("I am in relationshhip with wifi")

    elif 'joke' in command:
        talk(pyjokes.get_joke())
        talk("sorry for the lamest joke")

    elif 'open google browser' in command:
        try:
            urL = 'https://www.google.com'
            chrome_path = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
            webbrowser.register('chrome', None,
                                webbrowser.BackgroundBrowser(chrome_path))
            webbrowser.get('chrome').open_new_tab(urL)
            talk("Successfully opened chrome its upto you to search")
        except:
            webbrowser.Error

    elif 'google search' in command:
        word_to_search = command.replace('google search', '')
        response = GoogleSearch().search(word_to_search)
        print(response)
        for result in response.results:
            print("Title: " + result.title)
            talk("You can look for the following titles  " + result.title)

    elif 'weather' in command:
        # base URL
        BASE_URL = "https://api.openweathermap.org/data/2.5/weather?"
        talk("Which city weather are you looking for")
        try:
            with sr.Microphone() as source:
                print('listening weather...')
                city_voice = listener.listen(source)
                city = listener.recognize_google(city_voice)
                # city = '\"'+city.lower()+'\"'

                print(city)
                # city="bangalore"
                # API key API_KEY = "Your API Key"
                API_KEY = "b5a362ef1dc8e16c673dd5049aa98d8f"
                # upadting the URL
                URL = BASE_URL + "q=" + city + "&appid=" + API_KEY
                # HTTP request
                response = requests.get(URL)
                # checking the status code of the request
                if response.status_code == 200:
                    # getting data in the json format
                    data = response.json()
                    # getting the main dict block
                    main = data['main']
                    # getting temperature
                    temperature = main['temp']
                    # getting the humidity
                    humidity = main['humidity']
                    # getting the pressure
                    pressure = main['pressure']
                    # weather report
                    report = data['weather']
                    print(f"{CITY:-^30}")
                    print(f"Temperature: {temperature}")
                    print(f"Humidity: {humidity}")
                    print(f"Pressure: {pressure}")
                    print(f"Weather Report: {report[0]['description']}")
                    talk("Temperature in " + city + " is " + temperature +
                         " humidity is " + humidity + " pressure is " +
                         pressure + " and your final weather report" + report)
                else:
                    # showing the error message
                    print("Error in the HTTP request")
                    talk("Error in the HTTP request")
        except:
            talk("Hmmmmm, it looks like there is something wrong")

    elif 'news' in command:
        try:
            googlenews = GoogleNews()
            googlenews.set_lang('en')
            # googlenews.set_period('7d')
            # googlenews.set_time_range('02/01/2020', '02/28/2020')
            googlenews.set_encode('utf-8')

            talk("What news are you looking for")
            try:
                with sr.Microphone() as source:
                    print('listening news ...')
                    news_voice = listener.listen(source)
                    news_input = listener.recognize_google(news_voice)
                    news_input = news_input.lower()
                    print(news_input)
                    googlenews.get_news(news_input)
                    googlenews.search(news_input)
                    googlenews.get_page(2)
                    result = googlenews.page_at(2)
                    news = googlenews.get_texts()
                    print(news)
                    talk(news)
            except:
                print("Error")
                talk("Error in reading input")

        except:
            print("No news")
            talk(" I couldn't find any news on this day")

    elif 'play book' or 'read pdf' in command:
        talk("Which pdf do you want me to read")
        book_input = input()
        print(book_input)
        book = open(book_input, 'rb')
        # create pdfReader object
        pdfReader = PyPDF2.PdfFileReader(book)
        # count the total pages
        total_pages = pdfReader.numPages
        total_pages = str(total_pages)
        print("Total number of pages " + total_pages)
        talk("Total number of pages " + total_pages)
        # initialise speaker object
        # speaker = pyttsx3.init()
        # talk("Enter your starting page")
        # start_page = int(input())
        talk(
            " here are the options for you, you can press 1 to  Play a single page     2 to   Play between start and end points  and  3 to  Play the entire book "
        )
        talk("Enter your choice")
        choice = int(input())
        if (choice == 1):
            talk("Enter index number")
            page = int(input())
            page = pdfReader.getPage(page)
            text = page.extractText()
            talk(text)
            # speaker.say(text)
            # speaker.runAndWait()
        elif (choice == 2):
            talk("Enter starting page number")
            start_page = int(input())
            talk("Enter ending page number")
            end_page = int(input())
            for page in range(start_page + 1, end_page):
                page = pdfReader.getPage(start_page + 1)
                text = page.extractText()
                talk(text)
                # speaker.say(text)
                # speaker.runAndWait()
        elif (choice == 3):
            for page in range(total_pages + 1):
                page = pdfReader.getPage(page)
                text = page.extractText()
                talk(text)
                # speaker.say(text)
                # speaker.runAndWait()
        else:
            talk("Haha!! Please enter valid choice")
    else:
        talk(
            "Hiii Rashika, I am so bored can you please give me some proper commands"
        )
コード例 #3
0
def user_input_3():
    screen_clear()
    print("\n")
    print(Fore.RED + "       ..,;:ccccccc:;...")
    print(Fore.WHITE + "    ..,clllc:;;;;;;:cllc,.")
    print(Fore.RED + "   .,cllc,..............';;'.")
    print(Fore.WHITE + "  .;lol;......" + Fore.WHITE + "_______" + Fore.RED +
          "....;lol;.")
    print(Fore.RED + " .,lol;......" + Fore.WHITE + "/ _____/" + Fore.RED +
          ".....;lol;..  ")
    print(Fore.WHITE + " .coo......." + Fore.WHITE + "/ /" + Fore.RED +
          ".............coo")
    print(Fore.RED + ".'lol,....." + Fore.WHITE + "/ /" + Fore.RED +
          "............'lol,.")
    print(Fore.WHITE + ".,lol,...." + Fore.WHITE + "/ /_____" + Fore.RED +
          "........,lol,.")
    print(Fore.RED + ".,lol,...." + Fore.WHITE + "\______/" + Fore.RED +
          ".......,lol,.")
    print(Fore.WHITE + " .:ooc'.................:ooc'")
    print(Fore.RED + "  .'cllc'.............cllc.")
    print(Fore.RED + " [ 1  ] Schedule a message ")
    print(Fore.WHITE + " [ 2  ] See all the messages sent ")
    print(Fore.RED + " [ 3  ] Clear Logs ")
    print(Fore.WHITE + "\n [ 99  ] Return to main-menu ")
    choice = int(input(Fore.RED + "\n [ → ] Enter choice> : "))

    if choice == 1:
        executer()

    elif choice == 2:
        pywhatkit.showHistory()
        choice = input(" [ → ] Do you want to clear the logs? [Y/n] > : ")
        if choice == "Y" or choice == "y":
            f = open("pywhatkit_dbs.txt", "w")
            f.write("Woops! you have deleted the content! ")
            f.close()
            print(Fore.WHITE + Back.RED + "\n\tLogs cleared")
            sleep(1)
            user_input_3()

        elif choice == "n" or choice == "n":
            print("Returning Back")
            sleep(1)
            user_input_3()

        else:
            print("\n\t【X】wrong input!! TryAgain【X】")
            user_input_3()

    elif choice == 3:
        f = open("pywhatkit_dbs.txt", "w")
        f.write("No Logs ")
        f.close()
        print(Fore.WHITE + Back.RED + "\n\tLogs cleared")
        sleep(1)
        user_input_3()

    elif choice == 99:
        print("\n\t[ℂ] Returning to main-menu [ℂ]")
        sleep(1)
        bashCommand = "clear;. ./cyanide-framework.sh;main"
        output = subprocess.call(['bash', '-c', bashCommand])

    else:
        print("\n\t【X】wrong input!! Try Again【X】")
コード例 #4
0
import pywhatkit as kit
kit.sendwhatmsg("+91 **858 *****", "sending the meg with the help of python",9,42)
kit.showHistory()
コード例 #5
0
pywhatkit.sendwhatmsg_with_selenium(
    "Phone_Number", "This is a message", 15,
    00)  #Will send message with most of the processes hidden

pywhatkit.send_file(
    "phone_number", "Path to file", 15,
    00)  #Will send file to number with most of the processes hidden

pywhatkit.sendwhatmsg(
    "phone_number", "This is a message", 15, 00
)  #Will open web.whatsapp.com at 14:59 and message will be sent at exactly 15:00

pywhatkit.info("Python", lines=3,
               speak=None)  #Will give information about the topic

pywhatkit.playonyt(
    "Python")  #Will play the first YouTube video having "Python" in it

pywhatkit.search("Python")  #Will perform a Google search

pywhatkit.showHistory(
)  #Will show information of all the messages sent using this library

pywhatkit.shutdown(time=100)  #Will shutdown the system in 100 seconds

pywhatkit.cancelShutdown()  #Will cancel the scheduled shutdown

pywhatkit.watch_tutorial_in_english / hindi(
)  #Will open a tutorial on how to use this library on YouTube in respective language

pywhatkit.help()  #For more information