import ssd1306
import requests
#import urequests
import network
import time
import json
from machine import Pin,I2C
i2c = I2C( scl=Pin(22), sda=Pin(21), freq=400000)
display = ssd1306.SSD1306_I2C(128, 64, i2c,addr=0x3C)
print("Connecting to WiFi", end="")
sta_if = network.WLAN(network.STA_IF)
sta_if.active(True)
sta_if.connect('Wokwi-GUEST', '')
while not sta_if.isconnected():
print(".", end="")
time.sleep(0.1)
print(" Connected!\n")
latitude=input("Enter Latitude: ")
longitude=input("Enter Longitude: ")
api = "https://api.open-meteo.com/v1/forecast?latitude=" + str(latitude) + "&longitude=" + str(longitude) + "¤t=temperature_2m,wind_speed_10m&hourly=temperature_2m,relative_humidity_2m,wind_speed_10m"
json_data = requests.get(api).json()
time=json_data['current']['time']
temp=json_data['current']['temperature_2m']
wind_speed=json_data['current']['wind_speed_10m']
print("\nWeather Data:\n\nTime: "+str(time)+"\nTemperature: "+str(temp)+"\nWind Speed: "+str(wind_speed)+"\n")
display.contrast(255)
display.text("Latitude:"+str(latitude),0,0)
display.text("Longitude:"+str(longitude),0,10)
display.text("Time:"+str(time),0,20)
display.text("Temp:"+str(temp),0,30)
display.text("Wind Speed:"+str(wind_speed),0,40)
display.show()