aliceblue11 commited on
Commit
a5326d4
·
verified ·
1 Parent(s): c3fa335

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -2
app.py CHANGED
@@ -22,7 +22,8 @@ def scrape_naver_stock():
22
  rank = cols[0].text.strip()
23
  name = cols[1].text.strip()
24
  price = cols[2].text.strip()
25
- diff = cols[3].text.strip()
 
26
  change_rate = cols[4].text.strip()
27
  volume = cols[5].text.strip()
28
  buy_price = cols[6].text.strip()
@@ -38,10 +39,31 @@ def scrape_naver_stock():
38
 
39
  return df
40
 
 
 
 
 
 
 
 
41
  # 그라디오 UI
42
  def display_stocks():
43
  df = scrape_naver_stock()
44
  return df
45
 
46
- iface = gr.Interface(fn=display_stocks, inputs=[], outputs="dataframe")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
47
  iface.launch()
 
22
  rank = cols[0].text.strip()
23
  name = cols[1].text.strip()
24
  price = cols[2].text.strip()
25
+ # 전일비에서 상한가, 상승 등의 텍스트를 제거하고 숫자만 추출
26
+ diff = cols[3].text.strip().replace("상한가", "▲").replace("상승", "▲")
27
  change_rate = cols[4].text.strip()
28
  volume = cols[5].text.strip()
29
  buy_price = cols[6].text.strip()
 
39
 
40
  return df
41
 
42
+ # 엑셀 파일 저장 함수
43
+ def save_to_excel():
44
+ df = scrape_naver_stock()
45
+ file_path = "/mnt/data/naver_stock_data.xlsx" # Gradio에서 사용할 수 있는 파일 경로
46
+ df.to_excel(file_path, index=False)
47
+ return file_path
48
+
49
  # 그라디오 UI
50
  def display_stocks():
51
  df = scrape_naver_stock()
52
  return df
53
 
54
+ # 그라디오 인터페이스
55
+ with gr.Blocks() as iface:
56
+ # 스크래핑된 데이터 테이블 출력
57
+ stock_table = gr.DataFrame(label="상승 TOP 종목")
58
+ download_button = gr.Button("엑셀 파일 다운로드")
59
+
60
+ # 버튼 클릭 시 엑셀 파일 저장 및 다운로드 제공
61
+ download_output = gr.File()
62
+
63
+ # 버튼 클릭 시 데이터 업데이트
64
+ download_button.click(save_to_excel, outputs=download_output)
65
+
66
+ # 스크래핑된 데이터를 UI에 로드
67
+ iface.load(fn=display_stocks, inputs=[], outputs=stock_table)
68
+
69
  iface.launch()