1

I have the following code that I was able to use from another post to accomplish either opening a webpage from terminal given a user's input:

  def yes_no(answer):
      yes = set(['yes','y', 'ye', ''])
      no = set(['no','n'])

      while True:
          choice = input(answer).lower()
          if choice in yes:
            print('Now opening.')
            webbrowser.get('chrome').open_new('https://...')
            time.sleep(5)
            return True
          elif choice in no:
            print('Will not open.')
            time.sleep(5)
            return False
          else:
            print("Please respond with 'yes' or 'no'")

And I have been struggling to put a timer on this function. Goal is to allow user input but if no response is given, say, in 5 seconds the thread will continue with a message similar to that of 'Will not open' (as if the input was no).

My goal is to use run...

yes_no(f'Open Website? [y/n]')

which works now.

Thanks for the input!

eccadena
  • 171
  • 1
  • 8

0 Answers0