Kims12 commited on
Commit
fc8a307
Β·
verified Β·
1 Parent(s): 8fb1af8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -15
app.py CHANGED
@@ -1,3 +1,4 @@
 
1
  import requests
2
  from requests.adapters import HTTPAdapter
3
  from requests.packages.urllib3.util.retry import Retry
@@ -18,13 +19,14 @@ logger = logging.getLogger(__name__)
18
 
19
  class ProxyConfig:
20
  def __init__(self):
 
21
  self.proxy_base = {
22
- "username": "65d866e39dc83ab06068",
23
- "password": "aefb03d059da70e2",
24
- "host": "gw.dataimpulse.com",
25
  "ports": {
26
- "http": "823",
27
- "socks5": "824"
28
  }
29
  }
30
 
@@ -72,12 +74,13 @@ def setup_session():
72
 
73
  # μž¬μ‹œλ„ μ„€μ •
74
  retries = Retry(
75
- total=5,
76
- backoff_factor=1,
77
- status_forcelist=[500, 502, 503, 504],
78
- allowed_methods=["GET", "HEAD", "OPTIONS"]
79
  )
80
 
 
81
  session.headers.update({
82
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
83
  'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
@@ -93,13 +96,14 @@ def setup_session():
93
  'Sec-Fetch-User': '?1',
94
  'Upgrade-Insecure-Requests': '1',
95
  'Cache-Control': 'max-age=0',
96
- 'DNT': '1'
97
  })
98
 
 
99
  adapter = HTTPAdapter(
100
  max_retries=retries,
101
- pool_connections=100,
102
- pool_maxsize=100
103
  )
104
  session.mount('https://', adapter)
105
  session.mount('http://', adapter)
@@ -141,7 +145,7 @@ def extract_data_to_excel_and_html(page, board_select, custom_url=""):
141
  return None, "<p>νŽ˜μ΄μ§€ μˆ˜λŠ” 1-50 사이여야 ν•©λ‹ˆλ‹€.</p>"
142
 
143
  session = setup_session()
144
- # 직접 μž…λ ₯을 μ„ νƒν•œ 경우 custom_url μ‚¬μš©
145
  if board_select == "μ§μ ‘μž…λ ₯" and custom_url.strip():
146
  base_url = custom_url.strip()
147
  filename = f'custom_{datetime.now(pytz.timezone("Asia/Seoul")).strftime("%Y%m%d_%H%M%S")}.xlsx'
@@ -256,7 +260,6 @@ def extract_data_to_excel_and_html(page, board_select, custom_url=""):
256
  </thead>
257
  <tbody>
258
  """
259
-
260
  row = 1
261
  current_date = datetime.now().strftime("%Y.%m.%d")
262
 
@@ -536,7 +539,7 @@ with gr.Blocks(css=css) as demo:
536
  container=True
537
  )
538
 
539
- # board_select 값이 변경될 λ•Œ μ§μ ‘μž…λ ₯ μ„ νƒμ‹œ custom_url 보이도둝 μ—…λ°μ΄νŠΈ
540
  board_select.change(fn=update_custom_url_visibility, inputs=board_select, outputs=custom_url)
541
 
542
  status = gr.Textbox(
 
1
+ import os
2
  import requests
3
  from requests.adapters import HTTPAdapter
4
  from requests.packages.urllib3.util.retry import Retry
 
19
 
20
  class ProxyConfig:
21
  def __init__(self):
22
+ # ν™˜κ²½ λ³€μˆ˜μ—μ„œ ν”„λ‘μ‹œ 정보λ₯Ό κ°€μ Έμ˜΅λ‹ˆλ‹€.
23
  self.proxy_base = {
24
+ "username": os.environ.get("PROXY_USERNAME"),
25
+ "password": os.environ.get("PROXY_PASSWORD"),
26
+ "host": os.environ.get("PROXY_HOST"),
27
  "ports": {
28
+ "http": os.environ.get("PROXY_HTTP_PORT"),
29
+ "socks5": os.environ.get("PROXY_SOCKS5_PORT")
30
  }
31
  }
32
 
 
74
 
75
  # μž¬μ‹œλ„ μ„€μ •
76
  retries = Retry(
77
+ total=5, # 총 μž¬μ‹œλ„ 횟수
78
+ backoff_factor=1, # μž¬μ‹œλ„ κ°„ λŒ€κΈ° μ‹œκ°„ κ³„μˆ˜
79
+ status_forcelist=[500, 502, 503, 504], # μž¬μ‹œλ„ν•  HTTP μƒνƒœ μ½”λ“œ
80
+ allowed_methods=["GET", "HEAD", "OPTIONS"] # μž¬μ‹œλ„ν•  HTTP λ©”μ„œλ“œ
81
  )
82
 
83
+ # κΈ°λ³Έ 헀더 μ„€μ •
84
  session.headers.update({
85
  'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
86
  'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
 
96
  'Sec-Fetch-User': '?1',
97
  'Upgrade-Insecure-Requests': '1',
98
  'Cache-Control': 'max-age=0',
99
+ 'DNT': '1' # Do Not Track μš”μ²­
100
  })
101
 
102
+ # HTTPS μ–΄λŒ‘ν„° μ„€μ •
103
  adapter = HTTPAdapter(
104
  max_retries=retries,
105
+ pool_connections=100, # μ—°κ²° ν’€ 크기
106
+ pool_maxsize=100 # μ΅œλŒ€ μ—°κ²° 수
107
  )
108
  session.mount('https://', adapter)
109
  session.mount('http://', adapter)
 
145
  return None, "<p>νŽ˜μ΄μ§€ μˆ˜λŠ” 1-50 사이여야 ν•©λ‹ˆλ‹€.</p>"
146
 
147
  session = setup_session()
148
+ # 직접 μž…λ ₯ 선택 μ‹œ custom_url μ‚¬μš©
149
  if board_select == "μ§μ ‘μž…λ ₯" and custom_url.strip():
150
  base_url = custom_url.strip()
151
  filename = f'custom_{datetime.now(pytz.timezone("Asia/Seoul")).strftime("%Y%m%d_%H%M%S")}.xlsx'
 
260
  </thead>
261
  <tbody>
262
  """
 
263
  row = 1
264
  current_date = datetime.now().strftime("%Y.%m.%d")
265
 
 
539
  container=True
540
  )
541
 
542
+ # board_select κ°’ λ³€κ²½ μ‹œ custom_url ν…μŠ€νŠΈλ°•μŠ€ ν‘œμ‹œ/μˆ¨κΉ€ μ—…λ°μ΄νŠΈ
543
  board_select.change(fn=update_custom_url_visibility, inputs=board_select, outputs=custom_url)
544
 
545
  status = gr.Textbox(