import time

def emit_data(socketio, app):
    print("Called emit data")
    while True:
        time.sleep(1)
        with app.app_context():
            with app.test_client() as client:
                response = client.get('/api/dome/a')
                if response.status_code == 200:
                    data = response.json
                    print(data)
                    socketio.emit('api_data', data)
                else:
                    print("Error fetching data:", response.status_code)


def start(socketio, app):
    socketio.start_background_task(emit_data, socketio=socketio, app=app)
