ginipick commited on
Commit
4c853de
ยท
verified ยท
1 Parent(s): d203678

Upload 2 files

Browse files
Files changed (2) hide show
  1. app (28).py +82 -0
  2. requirements (9).txt +4 -0
app (28).py ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import requests
2
+ from bs4 import BeautifulSoup
3
+ import pandas as pd
4
+ import gradio as gr
5
+
6
+ def fetch_kosdaq_data():
7
+ # ๋„ค์ด๋ฒ„ ์ฆ๊ถŒ ์ฝ”์Šค๋‹ฅ URL
8
+ url = "https://finance.naver.com/sise/sise_rise.naver?sosok=1"
9
+
10
+ try:
11
+ # ์›น ํŽ˜์ด์ง€ ์š”์ฒญ
12
+ response = requests.get(url)
13
+ response.raise_for_status()
14
+ soup = BeautifulSoup(response.content, "html.parser")
15
+
16
+ # ํ…Œ์ด๋ธ” ๋ฐ์ดํ„ฐ ์ถ”์ถœ
17
+ table = soup.find("table", class_="type_2")
18
+ rows = table.find_all("tr")
19
+
20
+ data = []
21
+ for row in rows:
22
+ columns = row.find_all("td")
23
+ if len(columns) >= 12: # 12๊ฐœ ์—ด์ด ์žˆ๋Š” ํ–‰๋งŒ ์ฒ˜๋ฆฌ
24
+ try:
25
+ # ๋ฐ์ดํ„ฐ ํŒŒ์‹ฑ
26
+ rank = columns[0].get_text(strip=True)
27
+ name = columns[1].get_text(strip=True)
28
+ current_price = columns[2].get_text(strip=True)
29
+ diff = columns[3].get_text(strip=True)
30
+ change_rate = columns[4].get_text(strip=True)
31
+ volume = columns[5].get_text(strip=True)
32
+ buy_price = columns[6].get_text(strip=True)
33
+ sell_price = columns[7].get_text(strip=True)
34
+ buy_total = columns[8].get_text(strip=True)
35
+ sell_total = columns[9].get_text(strip=True)
36
+ per = columns[10].get_text(strip=True)
37
+ roe = columns[11].get_text(strip=True)
38
+
39
+ data.append([
40
+ rank, name, current_price, diff, change_rate,
41
+ volume, buy_price, sell_price, buy_total,
42
+ sell_total, per, roe
43
+ ])
44
+ except Exception as e:
45
+ print(f"Error parsing row: {e}")
46
+ continue
47
+
48
+ # DataFrame ์ƒ์„ฑ
49
+ columns = ["Rank", "Name", "Current Price", "Difference", "Change Rate",
50
+ "Volume", "Buy Price", "Sell Price", "Buy Total",
51
+ "Sell Total", "PER", "ROE"]
52
+ df = pd.DataFrame(data, columns=columns)
53
+ return df
54
+
55
+ except Exception as e:
56
+ print(f"Error occurred: {e}")
57
+ return None
58
+
59
+ def display_data():
60
+ df = fetch_kosdaq_data()
61
+ if df is not None and not df.empty:
62
+ return df
63
+ else:
64
+ return "Failed to fetch data or no data available. Please check the logs."
65
+
66
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์„ค์ •
67
+ def gradio_interface():
68
+ with gr.Blocks() as demo:
69
+ gr.Markdown("# ๋„ค์ด๋ฒ„ ์ฆ๊ถŒ ์ฝ”์Šค๋‹ฅ ๋ฐ์ดํ„ฐ ์Šคํฌ๋ž˜ํ•‘")
70
+ fetch_button = gr.Button("๋ฐ์ดํ„ฐ ๊ฐ€์ ธ์˜ค๊ธฐ")
71
+ output_table = gr.Dataframe(headers=["Rank", "Name", "Current Price", "Difference", "Change Rate",
72
+ "Volume", "Buy Price", "Sell Price", "Buy Total",
73
+ "Sell Total", "PER", "ROE"]) # ๋ช…์‹œ์  ์—ด ์ด๋ฆ„ ์ง€์ •
74
+
75
+ fetch_button.click(fn=fetch_kosdaq_data, inputs=[], outputs=output_table)
76
+
77
+ return demo
78
+
79
+ demo = gradio_interface()
80
+
81
+ if __name__ == "__main__":
82
+ demo.launch()
requirements (9).txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ beautifulsoup4==4.12.2
2
+ pandas==1.5.3
3
+ requests==2.31.0
4
+ gradio==3.41.0