PYTHON_WITH_MOHAMMAD Telegram 105
مرحله ۵: دریافت اطلاعات آب‌وهوا از API
برای دریافت اطلاعات آب‌وهوا، از API سایت OpenWeatherMap استفاده می‌کنیم.

اول باید تو سایت OpenWeatherMap ثبت‌نام کنی و یه API Key دریافت کنی.

https://openweathermap.org/api


import requests

def get_weather(city):
api_key = 'API_KEY' # API Key خودت رو اینجا قرار بده
url = f'http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric'
response = requests.get(url)
data = response.json()

if data['cod'] == 200:
weather = data['weather'][0]['description']
temp = data['main']['temp']
return f'وضعیت آب‌وهوا در {city}: {weather}, دما: {temp}°C'
else:
return 'شهر مورد نظر یافت نشد.'

def get_city(update: Update, context: CallbackContext):
city = update.message.text
weather_info = get_weather(city)
update.message.reply_text(weather_info)



tgoop.com/python_with_mohammad/105
Create:
Last Update:

مرحله ۵: دریافت اطلاعات آب‌وهوا از API
برای دریافت اطلاعات آب‌وهوا، از API سایت OpenWeatherMap استفاده می‌کنیم.

اول باید تو سایت OpenWeatherMap ثبت‌نام کنی و یه API Key دریافت کنی.

https://openweathermap.org/api


import requests

def get_weather(city):
api_key = 'API_KEY' # API Key خودت رو اینجا قرار بده
url = f'http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}&units=metric'
response = requests.get(url)
data = response.json()

if data['cod'] == 200:
weather = data['weather'][0]['description']
temp = data['main']['temp']
return f'وضعیت آب‌وهوا در {city}: {weather}, دما: {temp}°C'
else:
return 'شهر مورد نظر یافت نشد.'

def get_city(update: Update, context: CallbackContext):
city = update.message.text
weather_info = get_weather(city)
update.message.reply_text(weather_info)

BY آموزش پایتون و برنامه نویسی


Share with your friend now:
tgoop.com/python_with_mohammad/105

View MORE
Open in Telegram


Telegram News

Date: |

Among the requests, the Brazilian electoral Court wanted to know if they could obtain data on the origins of malicious content posted on the platform. According to the TSE, this would enable the authorities to track false content and identify the user responsible for publishing it in the first place. How to Create a Private or Public Channel on Telegram? Select: Settings – Manage Channel – Administrators – Add administrator. From your list of subscribers, select the correct user. A new window will appear on the screen. Check the rights you’re willing to give to your administrator. Today, we will address Telegram channels and how to use them for maximum benefit. In the next window, choose the type of your channel. If you want your channel to be public, you need to develop a link for it. In the screenshot below, it’s ”/catmarketing.” If your selected link is unavailable, you’ll need to suggest another option.
from us


Telegram آموزش پایتون و برنامه نویسی
FROM American