Geek7 commited on
Commit
d31c699
·
verified ·
1 Parent(s): 24169a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -10
app.py CHANGED
@@ -1,13 +1,19 @@
1
  import streamlit as st
2
- import yfinance as yf
3
  import pandas as pd
 
4
 
5
- def fetch_yfinance_data(symbol):
6
- data = yf.download(symbol, start="2024-02-04", end="2024-02-04", interval="5m")
7
- return data
 
 
 
 
 
8
 
9
  def main():
10
- st.title("Stock Trend Predictor")
11
 
12
  # User input for stock symbol
13
  symbol = st.text_input("Enter Stock Symbol (e.g., IBM):")
@@ -16,12 +22,26 @@ def main():
16
  st.warning("Please enter a valid stock symbol.")
17
  st.stop()
18
 
19
- # Fetch yfinance data
20
- stock_data = fetch_yfinance_data(symbol)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
- # Display the raw data
23
- st.subheader("Raw Data:")
24
- st.write(stock_data)
25
 
26
  if __name__ == "__main__":
27
  main()
 
1
  import streamlit as st
2
+ import requests
3
  import pandas as pd
4
+ from datetime import datetime
5
 
6
+ # Hard-coded API key for demonstration purposes
7
+ API_KEY = "QR8F9B7T6R2SWTAT"
8
+
9
+ def fetch_alpha_vantage_data(api_key, symbol):
10
+ url = f'https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol={symbol}&apikey={api_key}'
11
+ response = requests.get(url)
12
+ alpha_vantage_data = response.json()
13
+ return alpha_vantage_data
14
 
15
  def main():
16
+ st.title("Real-Time Stock Data")
17
 
18
  # User input for stock symbol
19
  symbol = st.text_input("Enter Stock Symbol (e.g., IBM):")
 
22
  st.warning("Please enter a valid stock symbol.")
23
  st.stop()
24
 
25
+ # Use the hard-coded API key
26
+ api_key = API_KEY
27
+
28
+ # Continuously fetch and display real-time data
29
+ while True:
30
+ # Fetch Alpha Vantage data
31
+ alpha_vantage_data = fetch_alpha_vantage_data(api_key, symbol)
32
+
33
+ # Extract relevant data from Alpha Vantage response
34
+ alpha_vantage_quote = alpha_vantage_data.get('Global Quote', {})
35
+ df = pd.DataFrame([alpha_vantage_quote])
36
+ df.index = [datetime.now()] # Use the current timestamp as the index
37
+ df = df.dropna(axis=0)
38
+
39
+ # Display the real-time data
40
+ st.subheader("Real-Time Data:")
41
+ st.write(df)
42
 
43
+ # Add a delay to avoid exceeding API rate limits
44
+ st.experimental_sleep(60) # Sleep for 60 seconds (adjust as needed)
 
45
 
46
  if __name__ == "__main__":
47
  main()