Advertisement
Davidbalazs

API openweathermap

Apr 6th, 2020
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. import json
  2.  
  3. with open ("config.json") as f:
  4.     config = json.load(f)
  5.    
  6. def do_connect():
  7.     import network
  8.     wlan = network.WLAN(network.STA_IF)
  9.     wlan.active(True)
  10.     if not wlan.isconnected():
  11.         print('connecting to network...')
  12.         wlan.connect(config["ssid"], config["ssid_password"])
  13.         while not wlan.isconnected():
  14.             pass
  15.     print('network config:', wlan.ifconfig())
  16.    
  17.  
  18. def getAPI():
  19.     import urequests
  20.     response = urequests.get("http://api.openweathermap.org/data/2.5/weather?id={yourAPIkey}&lang=hu&units=metric")
  21.     data = (response.json())
  22.     w = data["weather"][0]
  23.     print (w)  
  24.     response.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement