Update app.py
Browse files
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": "
|
23 |
-
"password": "
|
24 |
-
"host":
|
25 |
"ports": {
|
26 |
-
"http": "
|
27 |
-
"socks5": "
|
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 |
-
# μ§μ
|
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
|
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(
|