openfree commited on
Commit
3a0fa58
โ€ข
1 Parent(s): 82bb213

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -10
app.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.common.exceptions import WebDriverException
 
 
 
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
- driver.implicitly_wait(10)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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}
 
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}