In your provided code, there seems to be an issue with calling the getWeather() function from JavaScript. To address this, consider the following revised code:
Python code:
import eel
import pyowm
owm = pyowm.OWM("78e8414197f287eb489f857bf10fa96a")
@eel.expose
def getWeather(place):
mgr = owm.weather_manager()
observation = mgr.weather_at_place(place)
w = observation.weather
temp = w.temperature('celsius')['temp']
return temp
eel.init("web")
eel.start("main.html", size=(700, 700))
HTML code:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Weather</title>
<script type="text/javascript" src="/eel.js"></script>
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<input type="text" id="location" placeholder="Enter city and country" required="" value="New York, USA">
<button id="getWeatherButton">GET WEATHER</button>
<div id="result"></div>
<script type="text/javascript">
async function displayWeather() {
let place = document.getElementById("location").value;
let temp = await eel.getWeather(place)();
document.getElementById("result").innerHTML = temp;
}
eel.expose(displayWeather);
document.getElementById("getWeatherButton").onclick = displayWeather;
</script>
</body>
</html>
Please note the following changes:
The eel.start() function call is now placed after the eel.expose decorator and the getWeather() function definition.
The line eel.expose(displayWeather); is added before assigning the onclick event.
The size=(700, 700) argument is removed from the eel.start() function call. You can adjust the size using CSS styles.
By making these adjustments, the getWeather() function should be properly recognized and called from the JavaScript code.