From be1daf645af908863fbb012e889979f2ef1aed48 Mon Sep 17 00:00:00 2001 From: neptune Date: Tue, 27 Dec 2022 08:25:04 -0300 Subject: a --- cgi/post.py | 24 +++++++++++++++++++----- cgi/templates/home.rss | 1 + 2 files changed, 20 insertions(+), 5 deletions(-) (limited to 'cgi') diff --git a/cgi/post.py b/cgi/post.py index ba08ad2..b84b753 100644 --- a/cgi/post.py +++ b/cgi/post.py @@ -1016,7 +1016,7 @@ def cut_msg(message, limit): short_message = re.compile(r"&(.(?!;))*$", re.DOTALL | re.IGNORECASE).sub("", short_message) # Removes incomplete HTML return short_message -def getLastAge(board_type, limit, rss=False): +def getLastAge(board_type, limit): threads = [] if board_type in [0, 1]: @@ -1029,15 +1029,29 @@ def getLastAge(board_type, limit, rss=False): for post in threads: post['content'] = cut_msg(post['content'], Settings.HOME_LASTPOSTS_LENGTH) - if rss: - post['timestamp_formatted'] = datetime.datetime.fromtimestamp(post['timestamp']).strftime('%Y-%m-%dT%H:%M:%S%Z') - if post['board_type'] == 1: post['url'] = '/%s/read/%d/l10' % (post['dir'], post['timestamp']) else: post['url'] = '/%s/res/%d.html' % (post['dir'], post['id']) return threads + +def getNewPosts(limit, rss=False): + sql = "SELECT posts.id, 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" + posts = FetchAll(sql, (limit,)) + + for post in posts: + post['content'] = cut_msg(post['message'], Settings.HOME_LASTPOSTS_LENGTH) + + if rss: + post['timestamp_formatted'] = datetime.datetime.fromtimestamp(post['timestamp']).strftime('%Y-%m-%dT%H:%M:%S%Z') + + if post['board_type'] == 1: + post['url'] = '/%s/read/%d/l10' % (post['dir'], post['timestamp']) + else: + post['url'] = '/%s/res/%d.html' % (post['dir'], post['id']) + + return posts def getNewThreads(limit): threads = [] @@ -1083,7 +1097,7 @@ def regenerateHome(): f.close() if Settings.ENABLE_RSS: - rss_rendered = renderTemplate('home.rss', {'posts': getLastAge(-1, 10, True)} ) + rss_rendered = renderTemplate('home.rss', {'posts': getNewPosts(10, True)} ) f = open(Settings.HOME_DIR + "bai.rss", "w") try: f.write(rss_rendered) diff --git a/cgi/templates/home.rss b/cgi/templates/home.rss index d293861..1e5f552 100644 --- a/cgi/templates/home.rss +++ b/cgi/templates/home.rss @@ -18,6 +18,7 @@