A
A
Ahmedsaid2020-08-25 11:19:30
Python
Ahmedsaid, 2020-08-25 11:19:30

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) + " градусов "

here is my html code and a java script that was supposed to link it with python
<!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>

the essence of the code: it was supposed to show the weather in the city you selected when you press the button python itself (on the terminal) on and the html itself without each other work but could not connect them. When I run the python code from the terminal, nothing happens but it doesn’t give any errors,
5f44c97059f82463189574.png
I recently started learning programming and started with html and css, made 1-2 sites and then I wanted to write scripts in other languages, I chose python and from the beginning I started watching vidos and now I wanted to repeat this video https://www.youtube.com/watch?v=Gon0MvppfF8&t=85s and seemed to repeat all his actions but could not connect html with python please help

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2020-08-25
Rahim @axmedsaid

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')

Y
yamurlo, 2021-04-23
@yamurlo

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 question

Ask a Question

731 491 924 answers to any question