diff --git a/webpages/__pycache__/project.cpython-312.pyc b/webpages/__pycache__/project.cpython-312.pyc index 0e6c9a4cf..a42387e6a 100644 Binary files a/webpages/__pycache__/project.cpython-312.pyc and b/webpages/__pycache__/project.cpython-312.pyc differ diff --git a/webpages/buffteks.html b/webpages/buffteks.html index ec38c0f6e..8f91adc83 100644 --- a/webpages/buffteks.html +++ b/webpages/buffteks.html @@ -141,13 +141,13 @@ - + diff --git a/webpages/pythonx_lessons_pages/__pycache__/pythonx_lesson2.cpython-312.pyc b/webpages/pythonx_lessons_pages/__pycache__/pythonx_lesson2.cpython-312.pyc index 3b5a1def4..b0a485091 100644 Binary files a/webpages/pythonx_lessons_pages/__pycache__/pythonx_lesson2.cpython-312.pyc and b/webpages/pythonx_lessons_pages/__pycache__/pythonx_lesson2.cpython-312.pyc differ diff --git a/webpages/pythonx_lessons_pages/__pycache__/pythonx_lesson3.cpython-312.pyc b/webpages/pythonx_lessons_pages/__pycache__/pythonx_lesson3.cpython-312.pyc index 8d6101364..9d127dcd1 100644 Binary files a/webpages/pythonx_lessons_pages/__pycache__/pythonx_lesson3.cpython-312.pyc and b/webpages/pythonx_lessons_pages/__pycache__/pythonx_lesson3.cpython-312.pyc differ diff --git a/webpages/pythonx_lessons_pages/pythonx_lesson2.py b/webpages/pythonx_lessons_pages/pythonx_lesson2.py index e0ec8b714..c6aece0ee 100644 --- a/webpages/pythonx_lessons_pages/pythonx_lesson2.py +++ b/webpages/pythonx_lessons_pages/pythonx_lesson2.py @@ -38,3 +38,24 @@ def pythonx_lesson2(): ax.imshow(wordcloud, interpolation='bilinear') plt.axis("off") st.pyplot(fig) + + + + source_code = """ + import streamlit as st + from wordcloud import WordCloud + import matplotlib.pyplot as plt + + text = st.text_area("Please input text to analyze") + + if st.button("Analyze"): + # Create a WordCloud object + wordcloud = WordCloud(width=800, height=400, background_color='white').generate(text) + fig, ax = plt.subplots() + ax.imshow(wordcloud, interpolation='bilinear') + plt.axis("off") + st.pyplot(fig) + """ + st.divider() + st.subheader("**Source Code of the Sample App.**") + st.code(source_code, line_numbers=True) \ No newline at end of file diff --git a/webpages/pythonx_lessons_pages/pythonx_lesson3.py b/webpages/pythonx_lessons_pages/pythonx_lesson3.py index ef7be5f36..6aac0e814 100644 --- a/webpages/pythonx_lessons_pages/pythonx_lesson3.py +++ b/webpages/pythonx_lessons_pages/pythonx_lesson3.py @@ -75,3 +75,63 @@ def pythonx_lesson3(): st.success('Done') + source_code = """ + + from datetime import date, datetime + import streamlit as st + import yfinance as yf + import plotly.express as px + + # print text formatted by HTML + st.markdown( + "

Sample Stock Price App.

", + unsafe_allow_html=True) + + st.write( + 'We will use the code learned from previous lecture to build an online application for tracing stock price' + ) + + # print text in markdown + st.markdown("## **Check Stock Information**") + + # a list of stock names + stock_names = ['MSFT', 'AAPL', 'AMZN', 'GOOGL'] + # select a stock to check + target_stock = st.selectbox('Select a stock to check', options=stock_names) + + st.markdown("## **Check Stock Price History**") + + # start date of the stock infomation, default is the first day of year 2024 + start_date = st.date_input('Start Date', datetime(2024, 1, 1)) + # end date of the stock infomation, default is date of today + end_date = st.date_input("End Date") + + # get today date + today = date.today() + if st.button('Submit'): + # check valid date + if start_date > today or end_date > today: + st.write("## **Please select a valid date period.**") + else: + # download the stock data based on stock name, start/end date + data = yf.download(target_stock, start_date, end_date) + # show a progress bar + with st.spinner(text='In progress'): + + fig = px.line(data, + x=data.index, + y=['Open', 'High', 'Low', 'Close'], + title=target_stock + " Stock Price", + labels={ + "value": "Stock Price ($)", + "variable": "Price Type" + }) + st.write(fig) + st.success('Done') + + + """ + st.divider() + st.subheader("**Source Code of the Sample App.**") + + st.code(source_code, line_numbers=True) \ No newline at end of file