Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,6 +2,8 @@ from flask import Flask, render_template, request, jsonify
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
from collections import Counter
|
|
|
|
|
|
|
| 5 |
|
| 6 |
##############################################################################
|
| 7 |
# 1) ์ ์ญ ๋ณ์ & ๋๋ฏธ ๋ฐ์ดํฐ
|
|
@@ -24,7 +26,8 @@ def generate_dummy_spaces(count):
|
|
| 24 |
'title': f'Dummy Space {i+1}',
|
| 25 |
'description': 'This is a fallback dummy space.',
|
| 26 |
'likes': 100 - i,
|
| 27 |
-
|
|
|
|
| 28 |
'hardware': 'cpu',
|
| 29 |
'user': {
|
| 30 |
'avatar_url': 'https://huggingface.co/front/thumbnails/huggingface/default-avatar.svg',
|
|
@@ -242,20 +245,26 @@ def new_created_spaces():
|
|
| 242 |
"""
|
| 243 |
ensure_cache_loaded()
|
| 244 |
|
| 245 |
-
# createdAt
|
| 246 |
-
|
| 247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
sorted_by_new = sorted(
|
| 249 |
SPACE_CACHE,
|
| 250 |
-
key=lambda s: s
|
| 251 |
reverse=True
|
| 252 |
)
|
| 253 |
|
| 254 |
-
# ์ต๋
|
| 255 |
-
|
| 256 |
|
| 257 |
final = []
|
| 258 |
-
for i, sp in enumerate(
|
| 259 |
# rank๋ ๋จ์ i+1 ๋ก
|
| 260 |
detail = get_space_details(sp, i, 0)
|
| 261 |
if detail:
|
|
@@ -274,7 +283,6 @@ if __name__ == '__main__':
|
|
| 274 |
|
| 275 |
# -------------------
|
| 276 |
# index.html ์ ์ฒด ์์ฑ
|
| 277 |
-
# ์๋๋ ๊ธฐ์กด ์ฝ๋ + "New Created" ํญ ์ถ๊ฐ ๋ถ๋ถ
|
| 278 |
# -------------------
|
| 279 |
with open('templates/index.html', 'w', encoding='utf-8') as f:
|
| 280 |
f.write('''<!DOCTYPE html>
|
|
@@ -1447,7 +1455,7 @@ if __name__ == '__main__':
|
|
| 1447 |
}
|
| 1448 |
|
| 1449 |
// --------------------- NEW CREATED ---------------------
|
| 1450 |
-
// ์๋ก ์์ฑ๋ ์คํ์ด์ค(์ต์ ์
|
| 1451 |
function loadNewCreatedSpaces() {
|
| 1452 |
setLoading(true);
|
| 1453 |
fetch('/api/new-created-spaces')
|
|
@@ -1476,7 +1484,7 @@ if __name__ == '__main__':
|
|
| 1476 |
return;
|
| 1477 |
}
|
| 1478 |
|
| 1479 |
-
// ์ต์ ์์ฑ๋ ์คํ์ด์ค
|
| 1480 |
spaces.forEach((item) => {
|
| 1481 |
try {
|
| 1482 |
const {
|
|
@@ -1834,5 +1842,4 @@ if __name__ == '__main__':
|
|
| 1834 |
</html>
|
| 1835 |
''')
|
| 1836 |
|
| 1837 |
-
# Flask ์๋ฒ ์คํ
|
| 1838 |
app.run(host='0.0.0.0', port=7860)
|
|
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
from collections import Counter
|
| 5 |
+
from datetime import datetime
|
| 6 |
+
import dateutil.parser # โ ์ถ๊ฐ
|
| 7 |
|
| 8 |
##############################################################################
|
| 9 |
# 1) ์ ์ญ ๋ณ์ & ๋๋ฏธ ๋ฐ์ดํฐ
|
|
|
|
| 26 |
'title': f'Dummy Space {i+1}',
|
| 27 |
'description': 'This is a fallback dummy space.',
|
| 28 |
'likes': 100 - i,
|
| 29 |
+
# createdAt๋ ์์๋ก ์ถ๊ฐ (๋ชจ๋ ๋์ผ ๋ ์ง)
|
| 30 |
+
'createdAt': '2023-01-01T00:00:00.000Z',
|
| 31 |
'hardware': 'cpu',
|
| 32 |
'user': {
|
| 33 |
'avatar_url': 'https://huggingface.co/front/thumbnails/huggingface/default-avatar.svg',
|
|
|
|
| 245 |
"""
|
| 246 |
ensure_cache_loaded()
|
| 247 |
|
| 248 |
+
# createdAt์ด ISO8601 ํํ์ธ์ง ํ์ธ ํ ํ์ฑ. ์คํจ ์ datetime.min ์ฌ์ฉ
|
| 249 |
+
def parse_created_at(space):
|
| 250 |
+
date_str = space.get('createdAt', '')
|
| 251 |
+
try:
|
| 252 |
+
return dateutil.parser.isoparse(date_str)
|
| 253 |
+
except:
|
| 254 |
+
return datetime.min
|
| 255 |
+
|
| 256 |
+
# createdAt ๊ธฐ์ค์ผ๋ก ํ์ฑํ์ฌ ๋ด๋ฆผ์ฐจ์ ์ ๋ ฌ
|
| 257 |
sorted_by_new = sorted(
|
| 258 |
SPACE_CACHE,
|
| 259 |
+
key=lambda s: parse_created_at(s),
|
| 260 |
reverse=True
|
| 261 |
)
|
| 262 |
|
| 263 |
+
# ์ต๋ 100๊ฐ๊น์ง๋ง
|
| 264 |
+
newest_100 = sorted_by_new[:100]
|
| 265 |
|
| 266 |
final = []
|
| 267 |
+
for i, sp in enumerate(newest_100):
|
| 268 |
# rank๋ ๋จ์ i+1 ๋ก
|
| 269 |
detail = get_space_details(sp, i, 0)
|
| 270 |
if detail:
|
|
|
|
| 283 |
|
| 284 |
# -------------------
|
| 285 |
# index.html ์ ์ฒด ์์ฑ
|
|
|
|
| 286 |
# -------------------
|
| 287 |
with open('templates/index.html', 'w', encoding='utf-8') as f:
|
| 288 |
f.write('''<!DOCTYPE html>
|
|
|
|
| 1455 |
}
|
| 1456 |
|
| 1457 |
// --------------------- NEW CREATED ---------------------
|
| 1458 |
+
// ์๋ก ์์ฑ๋ ์คํ์ด์ค(์ต์ ์ 100๊ฐ) ๋ถ๋ฌ์ค๊ธฐ
|
| 1459 |
function loadNewCreatedSpaces() {
|
| 1460 |
setLoading(true);
|
| 1461 |
fetch('/api/new-created-spaces')
|
|
|
|
| 1484 |
return;
|
| 1485 |
}
|
| 1486 |
|
| 1487 |
+
// ์ต์ ์์ฑ๋ ์คํ์ด์ค 100๊ฐ๋ฅผ ํ์ํ๋ฏ๋ก, rank๋ i+1 ๋ก ๋จ์ ๋ถ์ฌ
|
| 1488 |
spaces.forEach((item) => {
|
| 1489 |
try {
|
| 1490 |
const {
|
|
|
|
| 1842 |
</html>
|
| 1843 |
''')
|
| 1844 |
|
|
|
|
| 1845 |
app.run(host='0.0.0.0', port=7860)
|