@dimavfox

Как достать значение переменной из функции Python?

Есть скрипт бота.
В нём есть функция parse(), которая парсит сайт и находит нужные значения: date, month, weather, sunset, sunrise и т.д
Мне нужно достать значение "date" и "month" в функции ( @bot.message_handler(commands=['today'])
def forecast_today(message): ). Как это сделать?
import telebot
import urllib.request
from bs4 import BeautifulSoup


def get_html(url):
	response = urllib.request.urlopen(url)
	return response.read()

def parse(html):
	soup = BeautifulSoup(html, features="html5lib")
	div = soup.find('div', class_='tabs')
	blocks = div.find('div', class_='main')
	day_name = blocks.find('p', class_='day-link')
	day_date = blocks.find('p', class_='date')
	day_month = blocks.find('p', class_='month')
	weather = blocks.find('div', class_="weatherIco").get('title')
	temperature_min = blocks.find('div', class_='min')
	temperature_max = blocks.find('div', class_='max')
	DayLight = soup.find('div', class_='infoDaylight')
	table = soup.find('table', class_='weatherDetails')
	rows = table.find_all('td', class_='p4')
	city = soup.find('div', class_='cityName')
	city_h1 = city.find('h1')

# НУЖНЫЕ ЗНАЧЕНИЯ
	date = day_date.text
	month = day_month.text
	humidity = rows[5].text
	pressure = rows[4].text
	min_t = temperature_min.text
	max_t = temperature_max.text
	daylight = DayLight.text.strip()
	sunset = daylight[:12]
	sunrise = daylight[12:].lstrip()
	Name_Of_City = city_h1.text.strip()

def main():
	parse(get_html(''))

token = ""
bot = telebot.TeleBot(token)

@bot.message_handler(commands=['start'])
def start_chat(message):
  bot.send_message(message.chat.id, "Привет! Я могу подсказать погоду - введи /today")

@bot.message_handler(commands=['today'])
def forecast_today(message):
  bot.send_message(message.chat.id, "Вы выбрали прогноз на сегодня - " + date + "/" + month + "! Введите ваш город!")


if __name__ == '__main__':
	bot.polling(none_stop=True)
  • Вопрос задан
  • 1096 просмотров
Пригласить эксперта
Ответы на вопрос 1
@OlegUnity
Напиши в функциях global и название
И юзай
Ответ написан
Комментировать
Ваш ответ на вопрос

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

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