MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.

    MM and Custom Python Script

    Scheduled Pinned Locked Moved General Discussion
    7 Posts 2 Posters 2.1k Views 2 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S Offline
      sdetweil @Extra
      last edited by

      @extra my code can be used to display, and fade out would be a css setting

      Sam

      How to add modules

      learning how to use browser developers window for css changes

      1 Reply Last reply Reply Quote 0
      • E Offline
        Extra @sdetweil
        last edited by

        @sdetweil So your PythonPrint module will let me run my python script as MM is running, correct?

        And how would I get the print statements to appear like the compliments (same font size, transitions. And if I have 2 sentences that need to be displayed it breaks up the words and fades them in/out in order)?

        So basically, I press a button(which unmutes my mic), say my command, and have the results displayed to MM.

        Here’s a sample of my python script:

        #-------------------------------------------------------------------------------------
                                    #Search Wikipedia (General Info)
            #-------------------------------------------------------------------------------------
            if ('weather' not in command): 
                if ('who is' in command) or ('what is the' in command) or ('what is a' in command) or ("what is" in command):
                    if ('time' not in command):
                        if ('news' not in command):
                            speak('Searching Wikipedia...')
                            command = command.replace("who is","")
                            command = command.replace("what is the","")
                            command = command.replace("what is a","")
                            command = command.replace("what is","")
                            results = wikipedia.summary(command, sentences = 2)
                            #----------------------
                            #Auto typing animation:
                            print("Baxter: ", end="")
                            for i in results:
                                sys.stdout.write(i)
                                sys.stdout.flush()
                                time.sleep(0.05)
                            print("\n")
                            #----------------------
                            speak(results) 
            #-------------------------------------------------------------------------------------
                            #Search Wolfram Alpha (Math/Conversions, Definitions)
            #-------------------------------------------------------------------------------------
            if ('weather' not in command):
                if ('news' not in command):
                    if ('calculate' in command) or ("what's" in command) or ('define' in command):
                        speak('Searching Wolfram Alpha...')
                        command = command.replace("calculate","")
                        command = command.replace("what's","")
                        command = command.replace("define","")
                        # Wolframalpha App Id
                        appId = ''
                        # Wolfram Instance
                        client = wolframalpha.Client(appId)
                        res = client.query(''.join(command))
                        results = next(res.results).text
                        #----------------------
                        #Auto typing animation:
                        print("Baxter: ", end="")
                        for i in results:
                            sys.stdout.write(i)
                            sys.stdout.flush()
                            time.sleep(0.05)
                        print("\n")
                        #----------------------
                        speak(results) 
        
        S 1 Reply Last reply Reply Quote 0
        • S Offline
          sdetweil @Extra
          last edited by

          @extra my code puts the stdout output of the python script onto the page

          you just need to specify css classes in custom.css

          try the sample… it launches a python script that runs forever and prints output, the node_helper gets it and sends to module

          module displays…

          			wrapper.innerHTML = this.config.message;
          			wrapper.className += "PythonPrint"
          

          so just set the class values in custom.css

          .MMM-PythonPrint .PythonPrint { 
             font-size:24px;
             color: yellow;
          }
          

          Sam

          How to add modules

          learning how to use browser developers window for css changes

          E 1 Reply Last reply Reply Quote 0
          • E Offline
            Extra @sdetweil
            last edited by Extra

            @sdetweil Thanks will do. I just got a little confused, thanks for the clarification.

            S 1 Reply Last reply Reply Quote 0
            • S Offline
              sdetweil @Extra
              last edited by

              @extra u can use my code as the base for what u need, but it does 95%

              splitting lines

              easy in JavaScript, split()

              how to handle the different lines… that’s your design and implementation
              my code assumes one blob of text.

              Sam

              How to add modules

              learning how to use browser developers window for css changes

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Enjoying MagicMirror? Please consider a donation!
              MagicMirror created by Michael Teeuw.
              Forum managed by Sam, technical setup by Karsten.
              This forum is using NodeBB as its core | Contributors
              Contact | Privacy Policy