import requests
import threading
import time
import webbrowser


from flask import Flask
app = Flask(__name__)

#@app.before_first_request
#def activate_job():
#    def run_job():
#        while True:
#            print("Run recurring task")
#            time.sleep(3)
#
#    thread = threading.Thread(target=run_job)
#    thread.start()

#def start_flask():
#    webbrowser.open_new('http://127.0.0.1:5000/')  # Go to flask website
#    #start_runner()
#    if __name__ == "__main__":
#        
#        app.run()

@app.route("/")
def hello():
    return "Hello World!"


def start_runner():
    def start_loop():
        not_started = True
        while not_started:
            print('In start loop')
            try:
                r = requests.get('http://127.0.0.1:5000/')
                if r.status_code == 200:
                    print('Server started, quiting start_loop')
                    not_started = False
                print(r.status_code)
            except:
                print('Server not yet started')
            time.sleep(2)

    print('Started runner')
    thread = threading.Thread(target=start_loop)
    thread.start()

if __name__ == "__main__":
    webbrowser.open_new('http://127.0.0.1:5000/')  # Go to flask website
    #start_runner()
    app.run()
