mattritchey commited on
Commit
3a197d1
·
1 Parent(s): c671966

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +51 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Created on Thu Jul 6 13:09:57 2023
4
+
5
+ @author: mritchey
6
+ """
7
+ import streamlit as st
8
+ import pandas as pd
9
+ import requests
10
+ import plotly.express as px
11
+
12
+ # Sidebars
13
+ address = st.sidebar.text_input("Address", "123 Main Street, Columbus, OH 43215")
14
+ start_date = st.sidebar.date_input("Start Date", pd.Timestamp(2022, 9, 1))
15
+ end_date = st.sidebar.date_input("End Date", pd.Timestamp(2022, 9, 30))
16
+ variable_select = st.sidebar.radio("Variable", ('temperature_2m','windspeed_10m'))
17
+
18
+ # 1. Geocode API
19
+ add_input = address.replace(', ', '%2C+').replace(' ', '+')
20
+ url_geocode = f'https://geocoding.geo.census.gov/geocoder/locations/onelineaddress?address={add_input}&benchmark=2020&format=json'
21
+ response_geocode = requests.get(url_geocode).json()
22
+
23
+ lat_lon = response_geocode['result']['addressMatches'][0]['coordinates']
24
+ df_address = pd.DataFrame(lat_lon, index=[0])
25
+
26
+ lon, lat = df_address.values[0]
27
+
28
+
29
+ # 2. Elevation API
30
+ url_elevation = f'https://epqs.nationalmap.gov/v1/json?x={lon}&y={lat}&units=Feet&wkid=4326&includeDate=False'
31
+ response_elevation = requests.get(url_elevation).json()
32
+ df_address['Elevation'] = response_elevation['value']
33
+
34
+
35
+ # 3. Weather API
36
+ start_date = start_date.strftime("%Y-%m-%d")
37
+ end_date = end_date.strftime("%Y-%m-%d")
38
+
39
+ url_weather = f'https://archive-api.open-meteo.com/v1/archive?latitude={lat}&longitude={lon}&start_date={start_date}&end_date={end_date}&hourly=temperature_2m,windspeed_10m&timezone=America%2FNew_York&temperature_unit=fahrenheit&windspeed_unit=ms&precipitation_unit=inch'
40
+ results_weather = requests.get(url_weather).json()
41
+ df_weather = pd.DataFrame(results_weather['hourly'])
42
+
43
+
44
+ # Display Dataframe
45
+ st.dataframe(df_address)
46
+
47
+ # Display Plotly Chart
48
+ wind = px.line(df_weather, x="time", y=variable_select)
49
+ st.plotly_chart(wind)
50
+
51
+ # To execute: streamlit run "C:\Users\mritchey\.spyder-py3\Python Scripts\streamlit projects\api web app\app.py"
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ requests
4
+ plotly