@newmaroluc

Как исправить ошибку программы погода?

Я делал программу Погода по уроку Хауди Хо.
Сделал все как на видео и до конца, но возникла проблема, подскажите что не так
Должно вывести погоду в указаном городе. И если раскомментировать вывод окно eel, то при нажатии на кнопку написано что нету переменной city, и в єтом скорее всего проблема, но в видео уроке так и было, скорее всего чтобы решить это нужно прописать что переменная city = тому что вводит пользователь. Как это сделать?
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:wght@300;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>
  • Вопрос задан
  • 156 просмотров
Решения вопроса 1
@newmaroluctwin
Правильный код:
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:wght@300;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
Ответ написан
Комментировать
Пригласить эксперта
Ответы на вопрос 1
@RRRRRRR7
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))
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы