-
-
Save em7v/8214373b51a2b2966d8baeed1bb17ed4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
import telebot | |
from telebot import apihelper | |
import socket | |
import socks | |
import pyowm | |
import math | |
ip = '95.216.224.183' # change your proxy's ip | |
port = 1080 # change your proxy's port | |
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, ip, port) | |
socket.socket = socks.socksocket | |
owm = pyowm.OWM() # Получаем ключ для погоды | |
bot = telebot.TeleBot() # Получаем ключ для бота | |
@bot.message_handler(content_types=['text']) | |
def send_echo(message): | |
try: | |
observation = owm.weather_at_place( message.text ) | |
w = observation.get_weather() | |
temp = w.get_temperature('celsius')["temp"] | |
temp_max = w.get_temperature('celsius')["temp_max"] | |
temp_min = w.get_temperature('celsius')["temp_min"] | |
wind = w.get_wind()["speed"] | |
status = w.get_detailed_status() | |
humidity = w.get_humidity() | |
t = round(temp) | |
t_max = math.ceil(temp_max) | |
t_min = math.floor(temp_min) | |
# wind_speed = round(wind) | |
cold = '' | |
chilly = '' | |
warm = '' | |
hot = '' | |
answer = "В городе " + message.text + " сейчас {}\n".format(str(status)) | |
answer += "Температура ~ {}°C \n".format(str(t)) | |
answer += "Макс. {}°C \n".format(str(t_max)) | |
answer += "Мин. {}°C \n".format(str(t_min)) | |
answer += "Влажность {}% \n".format(str(humidity)) | |
answer += "Скорость ветра составляет {} м/с \n\n".format(str(wind)) | |
if t <= 10: | |
answer += "На улице холодно, одевайся теплее!\n {}".format(cold) | |
elif t <= 18: | |
answer += "На улице прохладно, захвати с собой кофту!\n {}".format(chilly) | |
elif t <= 25: | |
answer += "На улице тепло, иди гуляй!\n {}".format(warm) | |
else: | |
answer += "На улице жара! Сиди под кондёром!\n {}".format(hot) | |
if w.get_detailed_status() == "дождь" or "легкий дождь": | |
answer += "Не забудь зонт, ты же не хочешь промокнуть?" | |
bot.send_message(message.chat.id, answer) | |
except Exception: | |
bot.send_message(message.chat.id, "Что-то пошло не так :(") | |
bot.polling( none_stop = True ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment