N
N
NEW MAROLUC2021-10-22 12:13:18
Python
NEW MAROLUC, 2021-10-22 12:13:18

How to fix weather program error?

I made the Weather program according to Howdy Ho's lesson.
I did everything as in the video and to the end, but there was a problem, tell me what's wrong
Should display the weather in the specified city. And if you uncomment the output of the eel window, then when you click on the button, it says that there is no variable city, and this is most likely a problem, but in the video lesson it was, most likely, to solve this, you need to write that the variable city = what the user enters. How to do it?

import eel
import pyowm

owm = pyowm.OWM("*******************")

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

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

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

  return "It is now " + str(temp) + "°" + " in " + city


HTML
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>Weather</title>
  <script src="eel.js"></script>
  <link rel="icon" type="image/png" href="favicon.png">
  <link rel="stylesheet" href="main.css">
  <link href="https://fonts.googleapis.com/css2?family=Roboto:[email protected];400;500&display=swap" rel="stylesheet">
</head>
<body>
  <input id="location" type="text", placeholder="Enter the name of the country and city..." required="" value="New York, NY, USA">
  <button id="show">Find out the weather</button>
  <div class="info">
  </div>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  <script type="text/javascript">
    // JS code for Python functions

    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

2 answer(s)
N
newmaroluctwin, 2021-10-22
@newmaroluc

Correct code:

import eel
import pyowm


owm = pyowm.OWM("*****ваш код*****")

@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 "It is now " + str(temp) + "°" + " in " + place


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

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Weatherice</title>

  <script src="eel.js"></script>
  <link rel="icon" type="image/png" href="/images/favicon.png">

  <link rel="stylesheet" href="main.css">
  <link href="https://fonts.googleapis.com/css2?family=Roboto:[email protected];400;500&display=swap" rel="stylesheet">
</head>
<body>

  <input id="location" type="text", placeholder="Enter the name of the country and city..." required="" value="New York, USA">

  <button id="show">Find out the weather</button>

    <hr noshade color="white" size="2">

  <div id="info"></div>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
  <script type="text/javascript">
    // JS code for Python functions

    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>

* {
  font-family: "Roboto", sans-serif;
  box-sizing: border-box;
  font-weight: 300;
}

body {
  background: #01b7a2; /* fallback for old browsers*/
  background: -webkit-linear-gradient(to right, #02a1b0, #00cd96); /* Chrome 10-25, Safari */
  background: linear-gradient(to right, #02a1b0, #00cd96); /* W3C, IE 10+/ Edge, Firefox */

  color: white;
  padding: 50px;
}

#location {
  display: block;
  border: none;
  background: rgba(255, 255, 255, 0.5);
  border-radius: 10px;
  padding: 20px;
  color: white;
  outline: none;
  width: 100%;
  font-size: 30px;
}

#location:placeholder {
  color: rgba(255, 255, 255, 0.5);
}

#show {
  display: block;
  border: none;
  margin-top: 15px;

  background: #ffb9af; /* fallback for old browsers*/
  background: -webkit-linear-gradient(to right, #ffc3a0, #ffafbd); /* Chrome 10-25, Safari */
  background: linear-gradient(to right, #ffc3a0, #ffafbd); /* W3C, IE 10+/ Edge, Firefox */

  border-radius: 10px;
  padding: 20px;
  color: white;
  outline: none;
  width: 100%;
  font-size: 20px;
  text-transform: uppercase;
  font-weight: bold;
  cursor: pointer;
}

#show:hover {
  opacity: .9;
}

hr {
    margin-top: 15px;
    margin-bottom: 15px;
    opacity: .5;
}

6172f9828bd60789436068.jpeg
6172f99223e33398528827.jpeg
6172f99e60d00065971543.jpeg

R
RRRRRRR7, 2021-10-22
@RRRRRRRR7

import eel
import pyowm

city = 'New York, USA'

owm = pyowm.OWM("*******************")

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

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

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

  return "It is now " + str(temp) + "°" + " in " + city


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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question