import network
import time
from dadjoke_fetcher import DadJokeFetcher
from facts_fetcher import FactsFetcher
from blinker import Blinker

fetcher1 = DadJokeFetcher()
fetcher2 = FactsFetcher()
blinker = Blinker(2)

def connect_to_wifi(ssid, password):
    station = network.WLAN(network.STA_IF)
    station.active(True)
    station.connect(ssid, password)
    
    while not station.isconnected():
        print("Connecting to WiFi...")
        blinker.blink(2, 0.3, 0.3)
    
    print("Connected to WiFi")
    blinker.blink(4, 0.4, 0.3)

SSID = "Wokwi-GUEST"
PASSWORD = ""
connect_to_wifi(SSID, PASSWORD)

while True:
    fetcher1.get_joke()
    time.sleep(5)
    fetcher2.get_fact()
    time.sleep(5)