-
Notifications
You must be signed in to change notification settings - Fork 1
/
bot.py
61 lines (43 loc) · 2.21 KB
/
bot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from decouple import config
import telebot,requests,math
from icons import icons
bot = telebot.TeleBot(config('BOT_TOKEN'))
api_address = config('address')
@bot.message_handler(commands=["start"])
def send_welcome(message):
bot.reply_to(message, f'''Hi👋, I am weather Bot, Thanks for starting me on,🛡️Build by <a href='tg://user?id=759684783'>DҽႦιρɾαʂαԃ</a>.''',parse_mode = "HTML")
@bot.message_handler(commands=["help"])
def send_help(message):
bot.reply_to(message, f"Ex: `/weather Kolkata`",parse_mode = "MARKDOWN")
@bot.message_handler(commands=["weather"])
def send_weather(message):
city = telebot.util.extract_arguments(message.text)
if not city:
bot.reply_to(message, "Please Enter a City!🙂")
else:
print("searching🌪️ for weather of🌞",city)
if city == 0:
bot.reply_to(message, "Weather not found!😅")
elif city != 0:
url = api_address + city
json_data = requests.get(url).json()
error_code = json_data['cod']
if error_code == 200:
city_name = json_data['name']
weather_data = json_data['weather'][0]['main']
wind_speed = json_data['wind']['speed']
icon = json_data['weather'][0]['icon']
formatted_data = json_data['main']['temp']
temp_data = formatted_data - 273.15
temp_data2 = math.floor(temp_data)
temp = str(temp_data2)+"°C"
for i in icons.keys():
if i==icon:
weather_icon = icons[i]
bot.reply_to(message, f'''🔹<i> The Weather 🌍 of <b> {city_name} </b> is :<b> {weather_data} </b> {weather_icon} \n🔹 The Temperature 🌡️ is Approx : <b>{temp} </b> \n🔹 The Wind 💨 Speed is : <b> {wind_speed} Km/h</b> </i>''',parse_mode = "HTML")
print("Request Successful 🤟")
else:
bot.reply_to(message,"City Not Found!😞 \nPlease Enter a Valid City.🙂")
else:
bot.reply_to(message,"Somethings goes wrong!😢")
bot.polling(none_stop=True)