P
P
Programist189462020-08-24 11:54:50
Python
Programist18946, 2020-08-24 11:54:50

Not outputting weather, weather python code using eel and pyowm libraries?

import eel 
import pyowm

owm = pyowm.OWM("8a1e96eb0d666fb9f233965c636924bf")

@eel.expose
def get_weather(place):
  mgr = owm.weather_manager()

  observation = mgr.weather_at_place(place)
  w = observation.weather

  temp = w.temperature('celsius')['temp']

  return "В городе " + place + "сейчас " + str(temp) + " градусов."

eel.init("web")
eel.start("main.html", size=(700 , 700))


HTML
<!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">
    <link href="https://fonts.googleapis.com/css2?family=Roboto:[email protected]&display=swap" rel="stylesheet">
  </head>
  <body>
    <input id="location" type="text" placeholder="Введите название: Город, Страна..." required="" >

    <button id="show">Нажать</button>
    <div class="info"></div>

    <script src="https://ajax.googleapis.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 answer(s)
S
soremix, 2020-08-24
@Programist18946

Press F12, open the console, you have all the errors written there.
On versions below 3 there is no manager. What do you have?

"AttributeError("'OWM25' object has no attribute 'weather_manager'",)"

You don't have a tag with ID info
Change from to
<div class="info"></div>
<div id="info"></div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question