TGViewer
آموزش پایتون و برنامه نویسی آموزش پایتون و برنامه نویسی @python_with_mohammad · 764 subscribers
Post #105 755
مرحله ۵: دریافت اطلاعات آب‌وهوا از 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)
openweathermap.org Weather API Explore OpenWeather's vast range of weather APIs including the versatile One Call API 4.0. Ideal for both beginners and professionals, our APIs offer current weather, minute-by-minute forecasts, historical data archives, and future predictions. Access weather…
More from @python_with_mohammad
  1. Sep 10, 2025درسنامه ایجنت‌های هوشمند (AI Agents) این نسخه ، برای اشنایی اولیه با AI Agents هست، لذا سع…
  2. Sep 4, 2025🚀 آینده هوش مصنوعی همین‌جاست و شما می‌توانید آن را بسازید! 🚀 تا حالا به این فکر کردی که…
  3. Aug 22, 2025🚀 می‌خوای پایتون یاد بگیری اما نمی‌دونی از کجا شروع کنی؟ من یک دوره‌ی آنلاین نیمه خصوصی م…
  4. Aug 5, 2025Post #126
  5. Aug 2, 2025قسمت ۱۳ ام ، فصل پردازش داده ها و یادگیری ماشین با داده های پزشکی موضوع: ارزیابی مدل و برر…
  6. Aug 2, 2025فصل پانزدهم دوره جامع پایتون و هوش مصنوعی با موضوع «پردازش و یادگیری ماشین با داده های عدد…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →