Update app.py
Browse files
app.py
CHANGED
|
@@ -1,54 +0,0 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import requests
|
| 3 |
-
import pandas as pd
|
| 4 |
-
|
| 5 |
-
# Hard-coded API key for demonstration purposes
|
| 6 |
-
API_KEY = "QR8F9B7T6R2SWTAT"
|
| 7 |
-
|
| 8 |
-
def fetch_alpha_vantage_data(api_key, symbol):
|
| 9 |
-
try:
|
| 10 |
-
url = f'https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol={symbol}&interval=5min&apikey={api_key}'
|
| 11 |
-
response = requests.get(url)
|
| 12 |
-
response.raise_for_status() # Raise an error for bad responses
|
| 13 |
-
alpha_vantage_data = response.json()
|
| 14 |
-
return alpha_vantage_data
|
| 15 |
-
except requests.RequestException as e:
|
| 16 |
-
st.error(f"Error fetching data: {e}")
|
| 17 |
-
return None
|
| 18 |
-
|
| 19 |
-
def main():
|
| 20 |
-
st.title("Stock Data Analysis")
|
| 21 |
-
|
| 22 |
-
# User input for stock symbol
|
| 23 |
-
symbol = st.text_input("Enter Stock Symbol (e.g., IBM):")
|
| 24 |
-
|
| 25 |
-
if not symbol:
|
| 26 |
-
st.warning("Please enter a valid stock symbol.")
|
| 27 |
-
st.stop()
|
| 28 |
-
|
| 29 |
-
# Use the hard-coded API key
|
| 30 |
-
api_key = API_KEY
|
| 31 |
-
|
| 32 |
-
# Fetch Alpha Vantage data
|
| 33 |
-
alpha_vantage_data = fetch_alpha_vantage_data(api_key, symbol)
|
| 34 |
-
|
| 35 |
-
if alpha_vantage_data:
|
| 36 |
-
# Extract relevant data from Alpha Vantage response
|
| 37 |
-
time_series_key = 'Time Series (5min)'
|
| 38 |
-
if time_series_key in alpha_vantage_data:
|
| 39 |
-
alpha_vantage_time_series = alpha_vantage_data[time_series_key]
|
| 40 |
-
df = pd.DataFrame(alpha_vantage_time_series).T
|
| 41 |
-
df.index = pd.to_datetime(df.index)
|
| 42 |
-
df = df.dropna(axis=0)
|
| 43 |
-
|
| 44 |
-
if not df.empty:
|
| 45 |
-
# Display the raw data
|
| 46 |
-
st.subheader("Raw Data:")
|
| 47 |
-
st.write(df)
|
| 48 |
-
else:
|
| 49 |
-
st.warning("No intraday data available for the specified symbol.")
|
| 50 |
-
else:
|
| 51 |
-
st.warning(f"Key '{time_series_key}' not found in API response.")
|
| 52 |
-
|
| 53 |
-
if __name__ == "__main__":
|
| 54 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|