pimoroni-pico-rp2350/micropython/examples/pico_plus_2_w/catfacts.py
2024-10-01 15:35:47 +01:00

23 lines
534 B
Python

"""
Get a cat fact from t'internet!
You will need to add your wireless SSID and password to secrets.py (and save this file to your Pico)
"""
import network
import requests
from secrets import SSID, PASSWORD
from time import sleep
# connect to wifi
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(SSID, PASSWORD)
while wlan.isconnected() is False:
print('Waiting for connection...')
sleep(1)
request = requests.get('http://catfact.ninja/fact').json()
fact = request['fact']
print('Cat fact!')
print(fact)