Spaces:
Sleeping
Sleeping
File size: 5,109 Bytes
79bddc3 ced7068 79bddc3 ced7068 3ae2ba3 ced7068 79bddc3 ced7068 79bddc3 ced7068 3ae2ba3 79bddc3 ced7068 79bddc3 ced7068 79bddc3 ced7068 fbf14cd 3fe0b2e ced7068 79bddc3 dd67806 ced7068 79bddc3 ced7068 a28c3c4 9004fd9 79bddc3 939c851 d7c68d1 79bddc3 371d5b1 f77ca12 79bddc3 72e8c78 ced7068 236dd28 9004fd9 34bf900 58d5310 79bddc3 ced7068 79bddc3 6c8f6ef 79bddc3 ced7068 5322473 ced7068 79bddc3 ced7068 79bddc3 ced7068 79bddc3 ced7068 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
import streamlit as st # for overall GUI
from streamlit_calendar import calendar # to show calendar
from dateutil.relativedelta import relativedelta # for addition to dates
import datetime
import os # for extracting environment variable
from urllib.request import urlopen # for getting data from FMP API
import json # for parsing data from FMP API
# For parsing data from API from JSON to a Python Dictionary
def get_jsonparsed_data(url):
response = urlopen(url)
data = response.read().decode("utf-8")
return json.loads(data)
# Get FMP API stored as environment variable
apiKey = os.environ['FMP_API_KEY']
# Financialmodelingprep (FMP) api base url
base_url = "https://financialmodelingprep.com/api/v3/"
# Get today's date and add 3 months to it
# Convert both today's date and the 3 months later date to strings (for input into API endpoint URL later)
# This is the date range within which we want to get our earnings dates
today = datetime.datetime.today()
today_string = today.strftime('%Y-%m-%d')
future_string = (today + relativedelta(months=3)).strftime('%Y-%m-%d')
# This is the full API endpoint to get the earnings dates from today to 6 months after
url = f"{base_url}earning_calendar?from={today_string}&to={future_string}&apikey={apiKey}"
# This decorator ensures that the call to the FMP API will only run once at the start of this app
# The data returned will be cached after the function runs
# Without this decorator, the API will be called each time you click something in the streamlit app
@st.cache_resource
def get_earnings_dates(url):
events = get_jsonparsed_data(url)
return events
events = get_earnings_dates(url)
with st.sidebar:
st.title("๋ฏธ๊ตญ ์ฃผ์ ์ด๋ ๋ฌ๋ ฅ")
st.header("์๊ณ ์ถ์ ๋ฏธ๊ตญ์ฃผ์ ํฐ์ปค๋ฅผ ์
๋ ฅํด์ฃผ์ธ์~")
#tickers = ['GOOG', 'META', 'TSLA', 'NET', 'V', 'MA', 'BA', 'C']
# For users to enter tickers of interest
tickers_string = st.text_area('๋ฌ๋ ฅ์ ํฌํจ๋ ํฐ์ปค๋ฅผ ,๋ก ๊ตฌ๋ถํด์ ์
๋ ฅํด์ฃผ์ธ์~ \
์ "NVDA, META, AMZN," ์
๋ ฅํ ์ปจํธ๋กค + ์ํฐ ๋๋ "์ ์ฉ" ๋ฒํผ ํด๋ฆญ ',
value = 'TSM,NVDA,AMD,INTC,MU,AAPL,GOOGL,FSLR,ARM,QCOM,MSFT,AMAT,LRCX,SNPS,CDNS,TSLA,ETN,FLNC,ANET,NXT,GEV,CRM,').upper()
st.button("์ ์ฉ")
st.write("๊ธฐ๋ณธ์ธํ
: ")
st.write("TSMC, Nvidia, AMD, Intel, Micron, Apple, ์ํ๋ฒณ,FirstSolar, ARM, Qualcomm, MS, Applied mat, Lam research, Synopsys, Cadence design, Tesla, Eaton,Fluence energy, Arista net, Nextracker, GE๋ฒ ๋ฅด๋
ธ๋ฐ, SalesForce")
st.write("์ฐธ๊ณ : Earnings ๋ ์ง๋ ์ค๋๋ถํฐ 3๊ฐ์ ์ด๋ด๋ก ์ ํ๋จ")
st.write('')
st.write("๋ฌ๋ ฅ์ ๋ฏธ๊ตญ์๊ฐ ๊ธฐ์ค์
๋๋ค.")
st.write("ํ๊ตญ ์๊ฐ ๊ธฐ์ค์ ์๋ ๋ด์ฉ ์ฐธ๊ณ .")
st.write("[์ฅ์ : ํ๊ตญ์๊ฐ ๋น์ผ ์ ๋
]")
st.write("[์ฅํ: ํ๊ตญ์๊ฐ ์ต์ผ ์์นจ]")
st.write('')
#st.markdown("## [Explanatory Article](https://medium.datadriveninvestor.com/build-a-stock-earnings-calendar-of-your-favorite-stocks-in-python-36bba1950a61)")
st.write('')
# Where the data came from
#st.markdown("## [Financial Modeling Prep API](https://intelligence.financialmodelingprep.com/pricing-plans?couponCode=damianboh&utm_campaign=damianboh&utm_medium=blog&utm_source=medium)\
#\n\nEarnings Dates for all tickers are obtained from the FinancialModelingPrep API, feel free to sign up\
#[here](https://intelligence.financialmodelingprep.com/pricing-plans?couponCode=damianboh&utm_campaign=damianboh&utm_medium=blog&utm_source=medium)\
#if you wish.")
# Parse user input into a list
tickers_string = tickers_string.replace(' ', '')
tickers = tickers_string.split(',')
# Converts the parsed json from FMP API into a list of events to be passed into streamlit_calendar
calendar_events = []
for event in events:
if event['symbol'] in tickers:
calendar_event = {}
calendar_event['title'] = event['symbol']
if event['time'] == 'bmo': # before market opens, add sunrise symbol
calendar_event['title'] = '์ฅ์ ' + calendar_event['title']
elif event['time'] == 'amc': # after market closes, add sunset symbol
calendar_event['title'] = '์ฅํ' + calendar_event['title']
calendar_event['start'] = event['date']
calendar_events.append(calendar_event)
st.header("๋ฏธ๊ตญ ์ฃผ์ ์ด๋ ๋ฌ๋ ฅ")
calendar_options = {
"editable": "true",
"navLinks": "true",
"headerToolbar": {
"left": "today prev,next",
"center": "title",
"right": "dayGridDay,dayGridWeek,dayGridMonth,listMonth",
},
#"initialDate": today.strftime('%Y-%m-%d'),
"initialView": "dayGridMonth"
}
custom_css="""
.fc-event-past {
opacity: 0.8;
}
.fc-event-time {
font-style: italic;
}
.fc-event-title {
font-weight: 700;
}
.fc-toolbar-title {
font-size: 2rem;
}
"""
calendar = calendar(events=calendar_events, options=calendar_options, custom_css=custom_css)
|