Back to articles
OpenWeatherMap API: Build a Weather Dashboard in 30 Lines

OpenWeatherMap API: Build a Weather Dashboard in 30 Lines

via Dev.toAlex Spinov

OpenWeatherMap gives you current weather, forecasts, air quality, and historical data for any location on Earth. Free. Here's how to build a useful weather dashboard in 30 lines. Setup Get a free API key at openweathermap.org (1,000 calls/day free) pip install httpx rich The Code import httpx from rich.console import Console from rich.table import Table API_KEY = ' your_free_api_key ' console = Console () def weather ( city ): r = httpx . get ( ' https://api.openweathermap.org/data/2.5/weather ' , params = { ' q ' : city , ' appid ' : API_KEY , ' units ' : ' metric ' }) d = r . json () return { ' city ' : d [ ' name ' ], ' temp ' : d [ ' main ' ][ ' temp ' ], ' feels_like ' : d [ ' main ' ][ ' feels_like ' ], ' humidity ' : d [ ' main ' ][ ' humidity ' ], ' wind ' : d [ ' wind ' ][ ' speed ' ], ' description ' : d [ ' weather ' ][ 0 ][ ' description ' ]. title (), ' pressure ' : d [ ' main ' ][ ' pressure ' ] } def dashboard ( cities ): table = Table ( title = ' Weather Dashboard ' ) t

Continue reading on Dev.to

Opens in a new tab

Read Full Article
2 views

Related Articles