Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app-backup.py
Browse files- app-backup.py +34 -11
app-backup.py
CHANGED
@@ -3,13 +3,17 @@ import gradio as gr
|
|
3 |
from datetime import datetime
|
4 |
import random
|
5 |
from selenium import webdriver
|
6 |
-
from selenium.
|
|
|
|
|
|
|
7 |
from PIL import Image
|
8 |
from io import BytesIO
|
9 |
import base64
|
|
|
10 |
|
11 |
def take_screenshot(url):
|
12 |
-
"""์น์ฌ์ดํธ ์คํฌ๋ฆฐ์ท ์ดฌ์ ํจ์"""
|
13 |
if not url.startswith('http'):
|
14 |
url = f"https://{url}"
|
15 |
|
@@ -22,14 +26,33 @@ def take_screenshot(url):
|
|
22 |
try:
|
23 |
driver = webdriver.Chrome(options=options)
|
24 |
driver.get(url)
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
screenshot = driver.get_screenshot_as_png()
|
27 |
img = Image.open(BytesIO(screenshot))
|
28 |
buffered = BytesIO()
|
29 |
img.save(buffered, format="PNG")
|
30 |
return base64.b64encode(buffered.getvalue()).decode()
|
|
|
31 |
except WebDriverException as e:
|
32 |
-
print(f"์คํฌ๋ฆฐ์ท ์ดฌ์ ์คํจ: {str(e)}")
|
|
|
|
|
|
|
33 |
return None
|
34 |
finally:
|
35 |
if 'driver' in locals():
|
@@ -297,8 +320,6 @@ def get_vercel_card(deployment, index, is_top_best=False):
|
|
297 |
url = f"https://{raw_url}"
|
298 |
|
299 |
name = deployment.get('name', '์ด๋ฆ ์๋ ํ๋ก์ ํธ')
|
300 |
-
created = format_timestamp(deployment.get('created'))
|
301 |
-
state = deployment.get('state', 'N/A')
|
302 |
|
303 |
# ์นด๋ ID ์์ฑ
|
304 |
card_id = f"vercel-card-{url.replace('.', '-').replace('/', '-')}"
|
@@ -307,6 +328,7 @@ def get_vercel_card(deployment, index, is_top_best=False):
|
|
307 |
screenshot_html = ""
|
308 |
if is_top_best:
|
309 |
try:
|
|
|
310 |
screenshot_base64 = take_screenshot(raw_url)
|
311 |
if screenshot_base64:
|
312 |
screenshot_html = f"""
|
@@ -316,14 +338,16 @@ def get_vercel_card(deployment, index, is_top_best=False):
|
|
316 |
alt="{name} ์คํฌ๋ฆฐ์ท"/>
|
317 |
</div>
|
318 |
"""
|
|
|
|
|
319 |
except Exception as e:
|
320 |
-
print(f"์คํฌ๋ฆฐ์ท ์ฒ๋ฆฌ ์ค๋ฅ: {str(e)}")
|
321 |
|
322 |
bg_color = get_pastel_color(index + (20 if not is_top_best else 0))
|
323 |
tech_emojis = ['โก', '๐', '๐', 'โจ', '๐ซ', '๐ฅ', '๐', '๐ฏ', '๐จ', '๐ฎ']
|
324 |
random_emojis = random.sample(tech_emojis, 3)
|
325 |
|
326 |
-
# Top Best
|
327 |
if is_top_best:
|
328 |
info_section = f"""
|
329 |
<div style='margin: 15px 0; color: #444; background: rgba(255,255,255,0.5);
|
@@ -338,10 +362,10 @@ def get_vercel_card(deployment, index, is_top_best=False):
|
|
338 |
<div style='margin: 15px 0; color: #444; background: rgba(255,255,255,0.5);
|
339 |
padding: 15px; border-radius: 12px;'>
|
340 |
<p style='margin: 8px 0;'>
|
341 |
-
<strong>Status:</strong> โ
{state}
|
342 |
</p>
|
343 |
<p style='margin: 8px 0;'>
|
344 |
-
<strong>Created:</strong> ๐
{created}
|
345 |
</p>
|
346 |
<p style='margin: 8px 0;'>
|
347 |
<strong>URL:</strong> ๐ {url}
|
@@ -641,7 +665,6 @@ def get_user_spaces():
|
|
641 |
(Plus {top_best_count} featured items in Top Best section)
|
642 |
</p>
|
643 |
</div>
|
644 |
-
|
645 |
<!-- Top Best -->
|
646 |
<h3 style='color: #333; margin: 20px 0;'>๐ Top Best</h3>
|
647 |
<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
|
|
|
3 |
from datetime import datetime
|
4 |
import random
|
5 |
from selenium import webdriver
|
6 |
+
from selenium.webdriver.support.ui import WebDriverWait
|
7 |
+
from selenium.webdriver.support import expected_conditions as EC
|
8 |
+
from selenium.webdriver.common.by import By
|
9 |
+
from selenium.common.exceptions import WebDriverException, TimeoutException
|
10 |
from PIL import Image
|
11 |
from io import BytesIO
|
12 |
import base64
|
13 |
+
import time
|
14 |
|
15 |
def take_screenshot(url):
|
16 |
+
"""์น์ฌ์ดํธ ์คํฌ๋ฆฐ์ท ์ดฌ์ ํจ์ (๋ก๋ฉ ๋๊ธฐ ์๊ฐ ์ถ๊ฐ)"""
|
17 |
if not url.startswith('http'):
|
18 |
url = f"https://{url}"
|
19 |
|
|
|
26 |
try:
|
27 |
driver = webdriver.Chrome(options=options)
|
28 |
driver.get(url)
|
29 |
+
|
30 |
+
# ๋ช
์์ ๋๊ธฐ: body ์์๊ฐ ๋ก๋๋ ๋๊น์ง ๋๊ธฐ (์ต๋ 10์ด)
|
31 |
+
try:
|
32 |
+
WebDriverWait(driver, 10).until(
|
33 |
+
EC.presence_of_element_located((By.TAG_NAME, "body"))
|
34 |
+
)
|
35 |
+
except TimeoutException:
|
36 |
+
print(f"ํ์ด์ง ๋ก๋ฉ ํ์์์: {url}")
|
37 |
+
|
38 |
+
# ์ถ๊ฐ ๋๊ธฐ ์๊ฐ (1์ด)
|
39 |
+
time.sleep(1)
|
40 |
+
|
41 |
+
# JavaScript ์คํ ์๋ฃ ๋๊ธฐ
|
42 |
+
driver.execute_script("return document.readyState") == "complete"
|
43 |
+
|
44 |
+
# ์คํฌ๋ฆฐ์ท ์ดฌ์
|
45 |
screenshot = driver.get_screenshot_as_png()
|
46 |
img = Image.open(BytesIO(screenshot))
|
47 |
buffered = BytesIO()
|
48 |
img.save(buffered, format="PNG")
|
49 |
return base64.b64encode(buffered.getvalue()).decode()
|
50 |
+
|
51 |
except WebDriverException as e:
|
52 |
+
print(f"์คํฌ๋ฆฐ์ท ์ดฌ์ ์คํจ: {str(e)} for URL: {url}")
|
53 |
+
return None
|
54 |
+
except Exception as e:
|
55 |
+
print(f"์์์น ๋ชปํ ์ค๋ฅ: {str(e)} for URL: {url}")
|
56 |
return None
|
57 |
finally:
|
58 |
if 'driver' in locals():
|
|
|
320 |
url = f"https://{raw_url}"
|
321 |
|
322 |
name = deployment.get('name', '์ด๋ฆ ์๋ ํ๋ก์ ํธ')
|
|
|
|
|
323 |
|
324 |
# ์นด๋ ID ์์ฑ
|
325 |
card_id = f"vercel-card-{url.replace('.', '-').replace('/', '-')}"
|
|
|
328 |
screenshot_html = ""
|
329 |
if is_top_best:
|
330 |
try:
|
331 |
+
print(f"์คํฌ๋ฆฐ์ท ์บก์ฒ ์๋: {url}") # ๋๋ฒ๊น
์ฉ ๋ก๊ทธ
|
332 |
screenshot_base64 = take_screenshot(raw_url)
|
333 |
if screenshot_base64:
|
334 |
screenshot_html = f"""
|
|
|
338 |
alt="{name} ์คํฌ๋ฆฐ์ท"/>
|
339 |
</div>
|
340 |
"""
|
341 |
+
else:
|
342 |
+
print(f"์คํฌ๋ฆฐ์ท ์บก์ฒ ์คํจ: {url}") # ๋๋ฒ๊น
์ฉ ๋ก๊ทธ
|
343 |
except Exception as e:
|
344 |
+
print(f"์คํฌ๋ฆฐ์ท ์ฒ๋ฆฌ ์ค๋ฅ: {str(e)} for URL: {url}") # ๋๋ฒ๊น
์ฉ ๋ก๊ทธ
|
345 |
|
346 |
bg_color = get_pastel_color(index + (20 if not is_top_best else 0))
|
347 |
tech_emojis = ['โก', '๐', '๐', 'โจ', '๐ซ', '๐ฅ', '๐', '๐ฏ', '๐จ', '๐ฎ']
|
348 |
random_emojis = random.sample(tech_emojis, 3)
|
349 |
|
350 |
+
# Top Best ์นด๋์ ๊ฐ์ํ๋ ์ ๋ณด ์น์
|
351 |
if is_top_best:
|
352 |
info_section = f"""
|
353 |
<div style='margin: 15px 0; color: #444; background: rgba(255,255,255,0.5);
|
|
|
362 |
<div style='margin: 15px 0; color: #444; background: rgba(255,255,255,0.5);
|
363 |
padding: 15px; border-radius: 12px;'>
|
364 |
<p style='margin: 8px 0;'>
|
365 |
+
<strong>Status:</strong> โ
{deployment.get('state', 'N/A')}
|
366 |
</p>
|
367 |
<p style='margin: 8px 0;'>
|
368 |
+
<strong>Created:</strong> ๐
{format_timestamp(deployment.get('created'))}
|
369 |
</p>
|
370 |
<p style='margin: 8px 0;'>
|
371 |
<strong>URL:</strong> ๐ {url}
|
|
|
665 |
(Plus {top_best_count} featured items in Top Best section)
|
666 |
</p>
|
667 |
</div>
|
|
|
668 |
<!-- Top Best -->
|
669 |
<h3 style='color: #333; margin: 20px 0;'>๐ Top Best</h3>
|
670 |
<div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
|