2023年4月16日 星期日

Find current weather of any city using OpenWeatherMap API in Python

import requests

# source: https://www.youtube.com/watch?v=I-xm8wVqO1o&t=1s
city = input("Enter a city name: ")
ApiKey = "cdd3be7d71fbdc5752c8b5b004957de4"
website = f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={ApiKey}"
WeatherInfo = requests.get(website)
temperature = int(WeatherInfo.json()["main"]["temp"]-273.15)
print(f"Current temperature in {city} is {temperature} degrees Celsius.")

沒有留言:

張貼留言

Python program to display calendar

# Python program to display calendar of given month of the year # importing calendar module for calendar operations import calendar # set t...