From 4c31093827f57394563de037a21143407586e384 Mon Sep 17 00:00:00 2001 From: Choom Date: Sun, 15 Jan 2023 03:12:48 -0300 Subject: Autorefresh en home --- cgi/api.py | 11 ++++++----- cgi/post.py | 13 ++++++++----- cgi/templates/feed.rss | 25 +++++++++++++++++++++++++ cgi/templates/home.html | 34 +++++++++++++++++++--------------- cgi/templates/home.rss | 25 ------------------------- cgi/templates/mobile/latest.html | 4 ++-- cgi/templates/mobile/newest.html | 4 ++-- cgi/weabot.py | 7 +++---- 8 files changed, 65 insertions(+), 58 deletions(-) create mode 100644 cgi/templates/feed.rss delete mode 100644 cgi/templates/home.rss (limited to 'cgi') diff --git a/cgi/api.py b/cgi/api.py index 871e88f..e6968f8 100644 --- a/cgi/api.py +++ b/cgi/api.py @@ -93,18 +93,19 @@ def api_process(self, path_split): data_limit = formdata.get('limit') data_time = formdata.get('time', 0) - limit = 30 - if data_limit: try: limit = int(data_limit) except ValueError: raise APIError("Limit must be numeric") - if limit > 50: - raise APIError("Maximum limit is 50") + if limit > 30: + raise APIError("Maximum limit is 30") + + threads = getLastAge(0, limit) + threads += getLastAge(1, limit) + threads = sorted(threads, key=lambda b:b['bumped'], reverse=True) - threads = getLastAge(limit) if threads[0]['bumped'] > int(data_time): values['threads'] = threads else: diff --git a/cgi/post.py b/cgi/post.py index c53e8a1..96b7cab 100644 --- a/cgi/post.py +++ b/cgi/post.py @@ -1080,11 +1080,13 @@ def cut_msg(message, limit): def getLastAge(board_type, limit): threads = [] + sql = "SELECT posts.id, boards.name AS board_name, boards.subname AS board_abr, board_type, boards.dir, timestamp, bumped, length, CASE WHEN posts.subject = boards.subject THEN posts.message ELSE posts.subject END AS content FROM posts INNER JOIN boards ON boardid = boards.id WHERE parentid = 0 AND IS_DELETED = 0 AND boards.secret = 0 AND posts.locked < 3" + if board_type in [0, 1]: - sql = "SELECT posts.id, boards.name AS board_fulln, boards.subname AS board_name, board_type, boards.dir, timestamp, length, CASE WHEN posts.subject = boards.subject THEN posts.message ELSE posts.subject END AS content FROM posts INNER JOIN boards ON boardid = boards.id WHERE parentid = 0 AND IS_DELETED = 0 AND boards.secret = 0 AND posts.locked < 3 AND boards.board_type = %s ORDER BY bumped DESC LIMIT %s" + sql += " AND boards.board_type = %s ORDER BY bumped DESC LIMIT %s" threads = FetchAll(sql, (board_type, limit) ) else: - sql = "SELECT posts.id, boards.name AS board_fulln, boards.subname AS board_name, board_type, boards.dir, timestamp, length, CASE WHEN posts.subject = boards.subject THEN posts.message ELSE posts.subject END AS content FROM posts INNER JOIN boards ON boardid = boards.id WHERE parentid = 0 AND IS_DELETED = 0 AND boards.secret = 0 AND posts.locked < 3 ORDER BY bumped DESC LIMIT %s" + sql += " ORDER BY bumped DESC LIMIT %s" threads = FetchAll(sql, (limit,) ) for post in threads: @@ -1098,7 +1100,7 @@ def getLastAge(board_type, limit): return threads def getNewPosts(limit, rss=False): - sql = "SELECT posts.id, parentid, boardid, boards.name AS board_fulln, board_type, boards.dir, timestamp, posts.message FROM posts INNER JOIN boards ON posts.boardid = boards.id WHERE IS_DELETED = 0 AND boards.secret = 0 ORDER BY timestamp DESC LIMIT %s" + sql = "SELECT posts.id, parentid, boardid, boards.name AS board_name, board_type, boards.dir, timestamp, posts.message FROM posts INNER JOIN boards ON posts.boardid = boards.id WHERE IS_DELETED = 0 AND boards.secret = 0 ORDER BY timestamp DESC LIMIT %s" posts = FetchAll(sql, (limit,)) for post in posts: @@ -1106,6 +1108,7 @@ def getNewPosts(limit, rss=False): if rss: post['timestamp_formatted'] = datetime.datetime.fromtimestamp(post['timestamp']).strftime('%Y-%m-%dT%H:%M:%S%Z') + post['content'] = cut_msg(post['message'], 100) if post['board_type'] == 1: post['url'] = '/%s/read/%d/l10' % (post['dir'], getParentTimestamp(post) or post['timestamp']) @@ -1116,7 +1119,7 @@ def getNewPosts(limit, rss=False): def getNewThreads(limit): threads = [] - sql = "SELECT posts.id, boards.name AS board_fulln, boards.subname AS board_name, board_type, boards.dir, timestamp, CASE WHEN posts.subject = boards.subject THEN posts.message ELSE posts.subject END AS content FROM posts INNER JOIN boards ON boardid = boards.id WHERE parentid = 0 AND IS_DELETED = 0 AND boards.secret = 0 AND boards.id <> 13 AND posts.locked = 0 ORDER BY timestamp DESC LIMIT %s" + sql = "SELECT posts.id, boards.name AS board_name, boards.subname AS board_abr, board_type, boards.dir, timestamp, CASE WHEN posts.subject = boards.subject THEN posts.message ELSE posts.subject END AS content FROM posts INNER JOIN boards ON boardid = boards.id WHERE parentid = 0 AND IS_DELETED = 0 AND boards.secret = 0 AND boards.id <> 13 AND posts.locked = 0 ORDER BY timestamp DESC LIMIT %s" threads = FetchAll(sql, (limit,) ) for post in threads: @@ -1158,7 +1161,7 @@ def regenerateHome(): f.close() if Settings.ENABLE_RSS: - rss_rendered = renderTemplate('home.rss', {'posts': getNewPosts(10, True)} ) + rss_rendered = renderTemplate('feed.rss', {'posts': getNewPosts(10, True)} ) f = open(Settings.HOME_DIR + "bai.rss", "w") try: f.write(rss_rendered) diff --git a/cgi/templates/feed.rss b/cgi/templates/feed.rss new file mode 100644 index 0000000..dfce578 --- /dev/null +++ b/cgi/templates/feed.rss @@ -0,0 +1,25 @@ + + + + Bienvenido a Internet BBS/IB + https://bienvenidoainternet.org/ + El BBS/IB más activo de la esfera hispana. + es + burocracia@bienvenidoainternet.org (Staff ★) + + https://bienvenidoainternet.org/rss_logo.png + Bienvenido a Internet BBS/IB + https://bienvenidoainternet.org/ + 144 + 144 + + + + ${post['board_name']}: #{post['content']} + ${post['timestamp_formatted']} + https://bienvenidoainternet.org#{post['url']} + ${post['content']} + + + + diff --git a/cgi/templates/home.html b/cgi/templates/home.html index d60b719..b5d932b 100644 --- a/cgi/templates/home.html +++ b/cgi/templates/home.html @@ -73,25 +73,29 @@ -

Hilos activos

-

BBS

-
+

Hilos activos

+

BBS

+
- [${thread['board_name']}:${'%03d' % thread['length']}] #{thread['content']} + [${thread['board_abr']}:${'%03d' % thread['length']}] #{thread['content']} -
-
-

IB

-
+
+
+

IB

+
- [${thread['board_name']}:${'%03d' % thread['length']}] #{thread['content']} + [${thread['board_abr']}:${'%03d' % thread['length']}] #{thread['content']} +
+
+
Actualizar + + + + + +
-
-
Actualizar - - - RSS

Blotter

@@ -107,7 +111,7 @@

Hilos nuevos

- [${thread['board_name']}] #{thread['content']} + [${thread['board_abr']}] #{thread['content']}
diff --git a/cgi/templates/home.rss b/cgi/templates/home.rss deleted file mode 100644 index 1e5f552..0000000 --- a/cgi/templates/home.rss +++ /dev/null @@ -1,25 +0,0 @@ - - - - Bienvenido a Internet BBS/IB - https://bienvenidoainternet.org/ - El BBS/IB más activo de la esfera hispana. - es - burocracia@bienvenidoainternet.org (Staff ★) - - https://bienvenidoainternet.org/rss_logo.png - Bienvenido a Internet BBS/IB - https://bienvenidoainternet.org/ - 144 - 144 - - - - ${post['board_fulln']}: #{post['content']} - ${post['timestamp_formatted']} - https://bienvenidoainternet.org#{post['url']} - ${post['message']} - - - - diff --git a/cgi/templates/mobile/latest.html b/cgi/templates/mobile/latest.html index 50fae25..8156e69 100644 --- a/cgi/templates/mobile/latest.html +++ b/cgi/templates/mobile/latest.html @@ -8,13 +8,13 @@

BBS

- #{thread['content']}
${thread['board_fulln']} R:#{int(thread['length'])-1}
+ #{thread['content']}
${thread['board_name']} R:#{int(thread['length'])-1}

IB

- #{thread['content']}
${thread['board_fulln']} R:#{int(thread['length'])-1}
+ #{thread['content']}
${thread['board_name']} R:#{int(thread['length'])-1}
diff --git a/cgi/templates/mobile/newest.html b/cgi/templates/mobile/newest.html index 37fd67f..76da88b 100644 --- a/cgi/templates/mobile/newest.html +++ b/cgi/templates/mobile/newest.html @@ -7,8 +7,8 @@
SeccionesHilos activosNuevos hilos
- #{thread['content']}
${thread['board_fulln']}
+ #{thread['content']}
${thread['board_name']}
- \ No newline at end of file + diff --git a/cgi/weabot.py b/cgi/weabot.py index 48f19f5..3ecf0f3 100755 --- a/cgi/weabot.py +++ b/cgi/weabot.py @@ -235,8 +235,8 @@ class weabot(object): self.output = renderTemplate('txt_newthread.html', {}, True) elif path_split[1] == "mobilehome": OpenDb() - latest_age_ib = getLastAge(0, Settings.HOME_LASTPOSTS) - latest_age_bbs = getLastAge(1, Settings.HOME_LASTPOSTS) + latest_age_ib = getLastAge(0, 10) + latest_age_bbs = getLastAge(1, 10) for threads in latest_age_ib: content = threads['url'] content = content.replace('/read/', '/') @@ -261,8 +261,7 @@ class weabot(object): content = content.replace('.html', '') threads['url'] = content caught = True - self.output = renderTemplate( - 'newest.html', {'newthreads': newthreads}, True) + self.output = renderTemplate('newest.html', {'newthreads': newthreads}, True) elif path_split[1] == "mobileread": OpenDb() board = setBoard(path_split[2]) -- cgit v1.2.1-18-gbd029