Answer the question
In order to leave comments, you need to log in
I can't connect python to html using javascript async function how can I do it differently?
here is my python code
import eel
import pyowm
owm=pyowm.OWM("11c0bcbf5628a90aa946468e636fb932")
@eel.expose
def get_weather():
mgr=owm.weather_manager()
observation=mgr.weather_at_place(city)
w=observation.weather
temp=w.temperature('celsius')['temp']
return "в городе "+ city + " сейчас "+ str(temp) + " градусов "
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Погода </title>
<script src="eel.js"></script>
<link rel="icon" type="image/png" href="/favicon.png">
<link rel="stylesheet" type="text/css" href="main.css">
</head>
<body>
<input id="location" type="text" placeholder="Введите название страны и города" required="" value="london">
<button id="show">Узнать погоду</button>
<div id="info"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript">
async function display_weather(){
let place=document.getElementById('location').value;
let res=await eel.get_weather(place);
document.getElementById('info').innerHTML=res;
}
jQuery('#show').on('click', function(){display_weather();});
</script>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
1. You rewrote the Python code incorrectly. Pass the city parameter to get_weather 2.
I advise you to close the howdy ho channel, his lessons are ridiculed, in my opinion, by everyone in the knowledgeable community. Well, you also need to add it to the end of the code. For some reason, this moment is not shown in the video, after wrapping it in a function
eel.init('web')
eel.start('main.html')
The python file needs these lines
eel.init("web")
eel.start('main.html', size = (700, 700))
It's just a typo and that's it.
def get_weather():
m g r=owm.weather_manager()
observation=m g r.weather_at_place(city)
w=observation.weather
temp=w.temperature('celsius')['temp']
return "in city "+ city + " now "+ str(temp) + " degrees "
Not mgr, but mrg. The letters were mixed up, so the weather did not give out.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question