YU-XI commited on
Commit
fb8274a
·
verified ·
1 Parent(s): ab0c85e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -18,6 +18,10 @@ st.title("🐣MOMO 🆚 PCHOME 商品搜索和價格分析👁️‍🗨️")
18
  search_keyword = st.text_input("請輸入要搜索的關鍵字: ", "筆電")
19
  page_number = st.number_input("請輸入要搜索的頁數: ", min_value=1, max_value=100, value=1, step=1)
20
 
 
 
 
 
21
  # Create a button to start the scraping process
22
  if st.button("開始搜索"):
23
  start_time = time.time()
@@ -173,13 +177,14 @@ if st.button("開始搜索"):
173
 
174
  # Pytrends Analysis
175
  pytrend = TrendReq(hl="zh-TW", tz=-480)
176
- keywords = search_keyword #20240204換關鍵字
177
  pytrend.build_payload(
178
  kw_list=keywords,
179
  cat=3,
180
- timeframe="2024-06-18 2024-06-24",
181
  geo="TW",
182
- gprop="")
 
183
 
184
  df = pytrend.interest_over_time()
185
  if "isPartial" in df.columns:
@@ -189,7 +194,7 @@ if st.button("開始搜索"):
189
  fig, ax = plt.subplots(figsize=(12, 8), dpi=80)
190
  ax.plot(df.index, df[keywords[0]], label=keywords[0], lw=3.0, marker='o', markersize=8, color='#4285F4', linestyle='-')
191
 
192
- ax.set_title("Interest Over Time for "+search_keyword, fontsize=20, fontweight='bold', color='#4285F4')
193
  ax.set_xlabel("時間", fontsize=14, fontweight='bold', color='#4285F4')
194
  ax.set_ylabel("熱搜度", fontsize=14, fontweight='bold', color='#4285F4')
195
  ax.legend()
@@ -213,4 +218,4 @@ if st.button("開始搜索"):
213
  st.pyplot(fig)
214
 
215
  # Print out statistics
216
- st.write(df.describe())
 
18
  search_keyword = st.text_input("請輸入要搜索的關鍵字: ", "筆電")
19
  page_number = st.number_input("請輸入要搜索的頁數: ", min_value=1, max_value=100, value=1, step=1)
20
 
21
+ # Date range input for Pytrends
22
+ start_date = st.date_input("選擇開始日期", value=datetime.today() - timedelta(days=30))
23
+ end_date = st.date_input("選擇結束日期", value=datetime.today())
24
+
25
  # Create a button to start the scraping process
26
  if st.button("開始搜索"):
27
  start_time = time.time()
 
177
 
178
  # Pytrends Analysis
179
  pytrend = TrendReq(hl="zh-TW", tz=-480)
180
+ keywords = [search_keyword] # 使用列表形式
181
  pytrend.build_payload(
182
  kw_list=keywords,
183
  cat=3,
184
+ timeframe=f"{start_date} {end_date}",
185
  geo="TW",
186
+ gprop=""
187
+ )
188
 
189
  df = pytrend.interest_over_time()
190
  if "isPartial" in df.columns:
 
194
  fig, ax = plt.subplots(figsize=(12, 8), dpi=80)
195
  ax.plot(df.index, df[keywords[0]], label=keywords[0], lw=3.0, marker='o', markersize=8, color='#4285F4', linestyle='-')
196
 
197
+ ax.set_title("Interest Over Time for " + search_keyword, fontsize=20, fontweight='bold', color='#4285F4')
198
  ax.set_xlabel("時間", fontsize=14, fontweight='bold', color='#4285F4')
199
  ax.set_ylabel("熱搜度", fontsize=14, fontweight='bold', color='#4285F4')
200
  ax.legend()
 
218
  st.pyplot(fig)
219
 
220
  # Print out statistics
221
+ st.write(df.describe())