Last active
July 11, 2019 09:16
-
-
Save AtenosFox/e87ad6295a350fbf4a36f0c7dfd0acf0 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 и port | |
ip = '95.216.224.183' | |
port = 1080 | |
socks.setdefaultproxy(socks.PROXY_TYPE_SOCKS5, ip, port) | |
socket.socket = socks.socksocket | |
owm = pyowm.OWM('', language = "ru") # Сюда вставляем ключ OWM | |
bot = telebot.TeleBot("") # Получаем ключ для бота от Telegram | |
@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) | |
answer = "В городе {} сейчас {}\n".format( message.text, 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" | |
elif t <= 18: | |
answer += "На улице прохладно, захвати с собой кофту!\n" | |
elif t <= 25: | |
answer += "На улице тепло, иди гуляй!\n" | |
else: | |
answer += "На улице жара!\n" | |
if str(status) == "дождь": | |
answer += "Не забудь зонт, ты же не хочешь промокнуть?" | |
elif str(status) == "легкий дождь": | |
answer += "Зонт возьми, вдруг польет сильнее?" | |
elif str(status) == "пасмурно" and (humidity > 50): | |
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