YU-XI commited on
Commit
abcb27a
·
verified ·
1 Parent(s): 33568c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -3
app.py CHANGED
@@ -7,6 +7,7 @@ import matplotlib.pyplot as plt
7
  import streamlit as st
8
  import json
9
  import time
 
10
 
11
  # Set up Streamlit app title
12
  st.title("🐣MOMO 🆚 PCHOME 商品搜索和價格分析👁️‍🗨️")
@@ -59,7 +60,7 @@ if st.button("開始搜索"):
59
  st.write(f"MOMO 最高價格: {momo_df['price'].max():.2f}")
60
  st.write(f"MOMO 最低價格: {momo_df['price'].min():.2f}")
61
 
62
- # MOMO visualization - Unified with PCHOME
63
  font_url = "https://drive.google.com/uc?id=1eGAsTN1HBpJAkeVM57_C7ccp7hbgSz3_&export=download"
64
  font_response = requests.get(font_url)
65
  with open("TaipeiSansTCBeta-Regular.ttf", "wb") as font_file:
@@ -93,7 +94,6 @@ if st.button("開始搜索"):
93
  pchome_json_data = json.loads(pchome_response.content)
94
  pchome_df = pd.DataFrame(pchome_json_data['prods'])
95
 
96
- # Safely select only available columns
97
  available_columns = ['name', 'describe', 'price', 'orig']
98
  selected_columns = [col for col in available_columns if col in pchome_df.columns]
99
  pchome_df = pchome_df[selected_columns]
@@ -141,4 +141,27 @@ if st.button("開始搜索"):
141
  )
142
 
143
  end_time = time.time()
144
- st.write(f"Execution time: {end_time - start_time:.2f} seconds")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  import streamlit as st
8
  import json
9
  import time
10
+ from pytrends.request import TrendReq
11
 
12
  # Set up Streamlit app title
13
  st.title("🐣MOMO 🆚 PCHOME 商品搜索和價格分析👁️‍🗨️")
 
60
  st.write(f"MOMO 最高價格: {momo_df['price'].max():.2f}")
61
  st.write(f"MOMO 最低價格: {momo_df['price'].min():.2f}")
62
 
63
+ # MOMO visualization
64
  font_url = "https://drive.google.com/uc?id=1eGAsTN1HBpJAkeVM57_C7ccp7hbgSz3_&export=download"
65
  font_response = requests.get(font_url)
66
  with open("TaipeiSansTCBeta-Regular.ttf", "wb") as font_file:
 
94
  pchome_json_data = json.loads(pchome_response.content)
95
  pchome_df = pd.DataFrame(pchome_json_data['prods'])
96
 
 
97
  available_columns = ['name', 'describe', 'price', 'orig']
98
  selected_columns = [col for col in available_columns if col in pchome_df.columns]
99
  pchome_df = pchome_df[selected_columns]
 
141
  )
142
 
143
  end_time = time.time()
144
+ st.write(f"Execution time: {end_time - start_time:.2f} seconds")
145
+
146
+ # Pytrends Analysis
147
+ pytrend = TrendReq(hl="zh-TW", tz=-480)
148
+ keywords = ["鴻屋"] #20240204換關鍵字
149
+ pytrend.build_payload(
150
+ kw_list=keywords,
151
+ cat=3,
152
+ timeframe="2024-06-18 2024-06-24",
153
+ geo="TW",
154
+ gprop="")
155
+
156
+ df = pytrend.interest_over_time()
157
+ df = df.drop(["isPartial"], axis=1)
158
+
159
+ # Plotting Trend Data
160
+ fig, ax = plt.subplots(figsize=(12, 8), dpi=80)
161
+ ax.plot(df.index, df[keywords[0]], label=keywords[0], lw=3.0, marker='o', markersize=8, color='#4285F4', linestyle='-')
162
+
163
+ ax.set_title("Interest Over Time for 鴻屋", fontsize=20, fontweight='bold', color='#4285F4')
164
+ ax.set_xlabel("時間", fontsize=14, fontweight='bold', color='#4285F4')
165
+ ax.set_ylabel("熱搜度", fontsize=14, fontweight='bold', color='#4285F4')
166
+ ax.legend()
167
+ ax.grid(True, linestyle