openfree commited on
Commit
c8d3bbf
โ€ข
1 Parent(s): fc8ae5a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -84
app.py CHANGED
@@ -193,50 +193,35 @@ def get_space_card(space, index):
193
  """
194
 
195
  def get_vercel_deployments():
196
- """Vercel API๋ฅผ ํ†ตํ•ด ๋ฐฐํฌ๋œ ์„œ๋น„์Šค ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ (ํŽ˜์ด์ง€๋„ค์ด์…˜ ์ ์šฉ)"""
197
  token = "A8IFZmgW2cqA4yUNlLPnci0N"
198
- base_url = "https://api.vercel.com/v6/deployments"
199
 
200
  headers = {
201
  "Authorization": f"Bearer {token}",
202
  "Content-Type": "application/json"
203
  }
204
 
205
- all_deployments = []
206
- next_page = None
207
-
208
  try:
209
- while True:
210
- # ๋‹ค์Œ ํŽ˜์ด์ง€๊ฐ€ ์žˆ์œผ๋ฉด ํ•ด๋‹น URL ์‚ฌ์šฉ, ์—†์œผ๋ฉด ๊ธฐ๋ณธ URL์— limit ์ ์šฉ
211
- url = next_page if next_page else f"{base_url}?limit=100"
212
-
213
- response = requests.get(url, headers=headers)
214
- if response.status_code != 200:
215
- print(f"Vercel API Error: {response.text}")
216
- break
217
-
218
- data = response.json()
219
- deployments = data.get('deployments', [])
220
- all_deployments.extend(deployments)
221
-
222
- # ๋‹ค์Œ ํŽ˜์ด์ง€ URL ํ™•์ธ
223
- pagination = data.get('pagination', {})
224
- next_page = pagination.get('next')
225
 
226
- # ๋‹ค์Œ ํŽ˜์ด์ง€๊ฐ€ ์—†์œผ๋ฉด ์ข…๋ฃŒ
227
- if not next_page:
228
- break
229
 
230
  # ์ƒํƒœ๊ฐ€ 'READY'์ด๊ณ  'url'์ด ์žˆ๋Š” ๋ฐฐํฌ๋งŒ ํ•„ํ„ฐ๋งํ•˜๊ณ  'javis1' ์ œ์™ธ
231
  active_deployments = [
232
- dep for dep in all_deployments
233
  if dep.get('state') == 'READY' and
234
  dep.get('url') and
235
  'javis1' not in dep.get('name', '').lower()
236
  ]
237
 
238
  return active_deployments
239
-
240
  except Exception as e:
241
  print(f"Error fetching Vercel deployments: {str(e)}")
242
  return []
@@ -553,11 +538,13 @@ def get_user_spaces():
553
  if not should_exclude_space(space.get('id', '').split('/')[-1])
554
  ]
555
 
556
- # Vercel ๋ฐฐํฌ ๊ฐ€์ ธ์˜ค๊ธฐ
557
- vercel_deployments = get_vercel_deployments()
558
 
559
- # TOP_BEST_URLS์˜ ๊ฐœ์ˆ˜๋„ ํฌํ•จ
560
- total_deployments = len(TOP_BEST_URLS) + (len(vercel_deployments) if vercel_deployments else 0)
 
 
561
 
562
  html_content = f"""
563
  <div style='padding: 20px; background-color: #f5f5f5;'>
@@ -571,12 +558,11 @@ def get_user_spaces():
571
  </a>
572
  </p>
573
  <p style='color: #666; margin: 0;'>
574
- Found {total_deployments} Vercel deployments and {len(user_spaces)} Hugging Face spaces
 
575
  </p>
576
  </div>
577
 
578
-
579
-
580
  <!-- Top Best -->
581
  <h3 style='color: #333; margin: 20px 0;'>๐Ÿ† Top Best</h3>
582
  <div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
@@ -585,10 +571,12 @@ def get_user_spaces():
585
  </div>
586
 
587
  <!-- Vercel Deployments -->
 
588
  <h3 style='color: #333; margin: 20px 0;'>โšก Vercel Deployments</h3>
589
  <div id="vercel-container" style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
590
  {"".join(get_vercel_card(dep, idx) for idx, dep in enumerate(vercel_deployments))}
591
  </div>
 
592
 
593
  <!-- Hugging Face Spaces -->
594
  <h3 style='color: #333; margin: 20px 0;'>๐Ÿค— Hugging Face Spaces</h3>
@@ -598,59 +586,9 @@ def get_user_spaces():
598
  </div>
599
 
600
  <script>
601
- document.addEventListener('DOMContentLoaded', function() {{
602
- // ์ข‹์•„์š” ์ƒํƒœ ๋กœ๋“œ
603
- function loadLikes() {{
604
- const cards = document.querySelectorAll('.vercel-card');
605
- cards.forEach(card => {{
606
- const cardId = card.id;
607
- const likes = localStorage.getItem(cardId) || 0;
608
- card.querySelector('.like-count').textContent = likes;
609
- card.dataset.likes = likes;
610
- updateLikeButton(card, likes > 0);
611
- }});
612
- sortCards();
613
- }}
614
-
615
- // ์ข‹์•„์š” ๋ฒ„ํŠผ ํ† ๊ธ€
616
- window.toggleLike = function(cardId) {{
617
- const card = document.getElementById(cardId);
618
- const likeCount = parseInt(localStorage.getItem(cardId) || 0);
619
- const newCount = likeCount > 0 ? 0 : 1;
620
-
621
- localStorage.setItem(cardId, newCount);
622
- card.querySelector('.like-count').textContent = newCount;
623
- card.dataset.likes = newCount;
624
- updateLikeButton(card, newCount > 0);
625
-
626
- sortCards();
627
- }}
628
-
629
- // ์ข‹์•„์š” ๋ฒ„ํŠผ ์ƒํƒœ ์—…๋ฐ์ดํŠธ
630
- function updateLikeButton(card, isLiked) {{
631
- const button = card.querySelector('.like-button');
632
- button.textContent = isLiked ? 'โค๏ธ' : '๐Ÿค';
633
- }}
634
-
635
- // ์นด๋“œ ์ •๋ ฌ
636
- function sortCards() {{
637
- const container = document.getElementById('vercel-container');
638
- const cards = Array.from(container.children);
639
-
640
- cards.sort((a, b) => {{
641
- return parseInt(b.dataset.likes) - parseInt(a.dataset.likes);
642
- }});
643
-
644
- cards.forEach(card => container.appendChild(card));
645
- }}
646
-
647
- // ์ดˆ๊ธฐ ๋กœ๋“œ
648
- loadLikes();
649
- }});
650
  </script>
651
  """
652
-
653
-
654
  return html_content
655
 
656
  except Exception as e:
 
193
  """
194
 
195
  def get_vercel_deployments():
196
+ """Vercel API๋ฅผ ํ†ตํ•ด ๋ฐฐํฌ๋œ ์„œ๋น„์Šค ์ •๋ณด ๊ฐ€์ ธ์˜ค๊ธฐ"""
197
  token = "A8IFZmgW2cqA4yUNlLPnci0N"
198
+ url = "https://api.vercel.com/v6/deployments?limit=100"
199
 
200
  headers = {
201
  "Authorization": f"Bearer {token}",
202
  "Content-Type": "application/json"
203
  }
204
 
 
 
 
205
  try:
206
+ response = requests.get(url, headers=headers)
207
+ print(f"Debug - Vercel API status code: {response.status_code}") # ๋””๋ฒ„๊น… ๋กœ๊ทธ
208
+ print(f"Debug - Vercel API response: {response.text[:500]}") # ์‘๋‹ต ๋‚ด์šฉ ์ผ๋ถ€ ์ถœ๋ ฅ
209
+
210
+ if response.status_code != 200:
211
+ print(f"Vercel API Error: {response.text}")
212
+ return []
 
 
 
 
 
 
 
 
 
213
 
214
+ deployments = response.json().get('deployments', [])
 
 
215
 
216
  # ์ƒํƒœ๊ฐ€ 'READY'์ด๊ณ  'url'์ด ์žˆ๋Š” ๋ฐฐํฌ๋งŒ ํ•„ํ„ฐ๋งํ•˜๊ณ  'javis1' ์ œ์™ธ
217
  active_deployments = [
218
+ dep for dep in deployments
219
  if dep.get('state') == 'READY' and
220
  dep.get('url') and
221
  'javis1' not in dep.get('name', '').lower()
222
  ]
223
 
224
  return active_deployments
 
225
  except Exception as e:
226
  print(f"Error fetching Vercel deployments: {str(e)}")
227
  return []
 
538
  if not should_exclude_space(space.get('id', '').split('/')[-1])
539
  ]
540
 
541
+ # TOP_BEST_URLS ํ•ญ๋ชฉ ์ˆ˜
542
+ top_best_count = len(TOP_BEST_URLS)
543
 
544
+ # Vercel API๋ฅผ ํ†ตํ•œ ์‹ค์ œ ๋ฐฐํฌ ์ˆ˜ (๋””๋ฒ„๊น…์„ ์œ„ํ•œ ์ถœ๋ ฅ ์ถ”๊ฐ€)
545
+ vercel_deployments = get_vercel_deployments()
546
+ print(f"Debug - Vercel API response: {vercel_deployments}") # ๋””๋ฒ„๊น… ๋กœ๊ทธ
547
+ actual_vercel_count = len(vercel_deployments) if vercel_deployments else 0
548
 
549
  html_content = f"""
550
  <div style='padding: 20px; background-color: #f5f5f5;'>
 
558
  </a>
559
  </p>
560
  <p style='color: #666; margin: 0;'>
561
+ Found {actual_vercel_count} Vercel deployments and {len(user_spaces)} Hugging Face spaces<br>
562
+ (Plus {top_best_count} featured items in Top Best section)
563
  </p>
564
  </div>
565
 
 
 
566
  <!-- Top Best -->
567
  <h3 style='color: #333; margin: 20px 0;'>๐Ÿ† Top Best</h3>
568
  <div style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
 
571
  </div>
572
 
573
  <!-- Vercel Deployments -->
574
+ {f'''
575
  <h3 style='color: #333; margin: 20px 0;'>โšก Vercel Deployments</h3>
576
  <div id="vercel-container" style='display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 20px;'>
577
  {"".join(get_vercel_card(dep, idx) for idx, dep in enumerate(vercel_deployments))}
578
  </div>
579
+ ''' if vercel_deployments else ''}
580
 
581
  <!-- Hugging Face Spaces -->
582
  <h3 style='color: #333; margin: 20px 0;'>๐Ÿค— Hugging Face Spaces</h3>
 
586
  </div>
587
 
588
  <script>
589
+ // ... (๊ธฐ์กด ์Šคํฌ๋ฆฝํŠธ ์ฝ”๋“œ๋Š” ๋™์ผํ•˜๊ฒŒ ์œ ์ง€)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
590
  </script>
591
  """
 
 
592
  return html_content
593
 
594
  except Exception as e: