DEV Community

Cover image for 1-Day Python Build: What’s The Weather At The North Pole?
Ryan
Ryan

Posted on • Originally published at anvil.works

1-Day Python Build: What’s The Weather At The North Pole?

What's the weather at the North Pole?

This blog post is part of Anvil's Advent Calendar, a project where we build 24 apps in 24 days, and blog about it! That means this app was built in only a few hours; read on to see what our 8th of December app is.

Weather conditions can be pretty tough for Santa Claus and his Elves at the North Pole. With todays advent calendar app, you can find out whether the weather is being naughty or nice for Santa:

https://north-pole-weather.anvil.app

Finished Weather App

Of course, the app is built with nothing but Python!

Here's how it works:

AccuWeather provides a simple free API for getting the current weather conditions at a given location. All we need to do is send a request to the API and build a front end for it to display the information we want.

We can start by building the app's UI by dragging and dropping components, like Labels, to display the weather information we want.

Dragging and dropping a Label onto a form and naming it self.chance_of_snow

Then we just need to get an API key and store it as a secret in our app. We can then create a server function to send the HTTP request and get weather data back:

`@anvil.server.callable
def get_north_pole_weather():
  resp = anvil.http.request(f"http://dataservice.accuweather.com/currentconditions/v1/336714?apikey={anvil.secrets.get_secret('accuweather_key')}", json=True)
  return resp[0]
Enter fullscreen mode Exit fullscreen mode

Then, we can set the properties of each front-end component, like a Label's display text, in client-side Python to display the weather data:

...
self.weather_description.text = weather_data['WeatherText']
self.temperature_celsius.text = str(weather_data['Temperature']['Metric']['Value']) + "°C"
...
Enter fullscreen mode Exit fullscreen mode

And that’s all there is to it! We now have an app to check the weather at the North Pole.

See the Source

Check out the source code for yourself!

Clone Link

Top comments (0)