averye-duke commited on
Commit
d8eff62
·
1 Parent(s): e008acb
Files changed (4) hide show
  1. requirements.txt +2 -2
  2. src/.env +1 -0
  3. src/func.py +35 -0
  4. src/streamlit_app.py +10 -36
requirements.txt CHANGED
@@ -1,3 +1,3 @@
1
- altair
2
- pandas
3
  streamlit
 
1
+ requests
2
+ dotenv
3
  streamlit
src/.env ADDED
@@ -0,0 +1 @@
 
 
1
+ OPENWEATHER_API_KEY = affa4f93a0cbf32b36ea6a33e34ce132
src/func.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ import os
3
+ from dotenv import load_dotenv
4
+
5
+ # Load your API key from .env file
6
+ load_dotenv()
7
+ API_KEY = os.getenv("OPENWEATHER_API_KEY")
8
+
9
+ def get_weather(city):
10
+ """
11
+ This function takes an city name as input, then uses the Open Weather API to
12
+ retrieve temp in celsius, humidity, and description
13
+ """
14
+
15
+ url = "https://api.openweathermap.org/data/2.5/weather"
16
+
17
+ params = {
18
+ "q": city,
19
+ "appid": API_KEY,
20
+ "units": "metric" # temperature in Celsius
21
+ }
22
+
23
+ response = requests.get(url, params=params)
24
+
25
+ data = response.json()
26
+
27
+ humidity = data["main"]["humidity"]
28
+ temp = data["main"]["temp"]
29
+ description = data["weather"][0]["description"]
30
+
31
+ return temp, humidity, description
32
+ # print(f"City = {city}")
33
+ # print(f"Temperature = {temp}")
34
+ # print(f"Humidity = {humidity}")
35
+ # print(f"Description = {description}")
src/streamlit_app.py CHANGED
@@ -1,40 +1,14 @@
1
- import altair as alt
2
- import numpy as np
3
- import pandas as pd
4
  import streamlit as st
 
5
 
6
- """
7
- # Welcome to Streamlit!
8
 
9
- Edit `/streamlit_app.py` to customize this app to your heart's desire :heart:.
10
- If you have any questions, checkout our [documentation](https://docs.streamlit.io) and [community
11
- forums](https://discuss.streamlit.io).
12
 
13
- In the meantime, below is an example of what you can do with just a few lines of code:
14
- """
15
-
16
- num_points = st.slider("Number of points in spiral", 1, 10000, 1100)
17
- num_turns = st.slider("Number of turns in spiral", 1, 300, 31)
18
-
19
- indices = np.linspace(0, 1, num_points)
20
- theta = 2 * np.pi * num_turns * indices
21
- radius = indices
22
-
23
- x = radius * np.cos(theta)
24
- y = radius * np.sin(theta)
25
-
26
- df = pd.DataFrame({
27
- "x": x,
28
- "y": y,
29
- "idx": indices,
30
- "rand": np.random.randn(num_points),
31
- })
32
-
33
- st.altair_chart(alt.Chart(df, height=700, width=700)
34
- .mark_point(filled=True)
35
- .encode(
36
- x=alt.X("x", axis=None),
37
- y=alt.Y("y", axis=None),
38
- color=alt.Color("idx", legend=None, scale=alt.Scale()),
39
- size=alt.Size("rand", legend=None, scale=alt.Scale(range=[1, 150])),
40
- ))
 
 
 
 
1
  import streamlit as st
2
+ from func import get_weather
3
 
4
+ st.title("Weather App")
5
+ city = st.text_input("What city would you like to know the weather for?")
6
 
7
+ st.image("https://media.istockphoto.com/id/1257525705/photo/the-changes-of-weather-a-natural-phenomenon-of-the-differences-of-four-seasons.jpg?s=612x612&w=0&k=20&c=pd2FEbZITpqphzEJ51FBQFexzniU0AZNJctpksrehYQ=", use_column_width=True)
 
 
8
 
9
+ if city:
10
+ temp, humidity, description = get_weather(city)
11
+ st.write("Welcome to", city)
12
+ st.write("Temperature is", temp)
13
+ st.write("Humidity is", humidity)
14
+ st.write("The skies show", description)