aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Choom 2022-12-19 04:07:15 -0300
committerLibravatar Choom 2022-12-20 01:12:19 -0300
commitbf739f69d56825b846a732e45dd5752ba84a3e5e (patch)
tree434493eaca7786cc8e55885b7473d025e4c05567
parente8a9779a6909e8e9bb5206f122d876c556b803a2 (diff)
downloadweabot-bf739f69d56825b846a732e45dd5752ba84a3e5e.tar.gz
weabot-bf739f69d56825b846a732e45dd5752ba84a3e5e.tar.xz
weabot-bf739f69d56825b846a732e45dd5752ba84a3e5e.zip
Fix rss
-rw-r--r--cgi/post.py89
-rw-r--r--cgi/templates/home.rss4
-rwxr-xr-xcgi/weabot.py11
3 files changed, 33 insertions, 71 deletions
diff --git a/cgi/post.py b/cgi/post.py
index b524d22..ba08ad2 100644
--- a/cgi/post.py
+++ b/cgi/post.py
@@ -492,11 +492,11 @@ def regenerateThreadPage(postid):
template_filename = "txt_thread.html"
outname = Settings.ROOT_DIR + board["dir"] + "/res/" + str(thread["timestamp"]) + ".html"
title_matome = thread['subject']
- post_preview = cut_home_msg(thread['posts'][0]['message'], 0)
+ post_preview = cut_msg(thread['posts'][0]['message'], Settings.HOME_LASTPOSTS_LENGTH)
else:
template_filename = "board.html"
outname = Settings.ROOT_DIR + board["dir"] + "/res/" + str(postid) + ".html"
- post_preview = cut_home_msg(thread['posts'][0]['message'], len(board['name']))
+ post_preview = cut_msg(thread['posts'][0]['message'], (Settings.HOME_LASTPOSTS_LENGTH - len(board['name'])) )
if thread['posts'][0]['subject'] != board['subject']:
title_matome = thread['posts'][0]['subject']
@@ -652,7 +652,7 @@ def dynamicRead(parentid, ranges, mobile=False):
if not filtered_thread["posts"]:
raise UserError("No hay posts que mostrar.")
- post_preview = cut_home_msg(filtered_thread["posts"][0]["message"], 0)
+ post_preview = cut_msg(filtered_thread['posts'][0]['message'], Settings.HOME_LASTPOSTS_LENGTH)
return renderTemplate(template_fname, {"threads": [filtered_thread], "replythread": parentid, "prevrange": prevrange, "nextrange": nextrange, "preview": post_preview}, mobile, noindex=True)
@@ -1016,22 +1016,21 @@ def cut_msg(message, limit):
short_message = re.compile(r"&(.(?!;))*$", re.DOTALL | re.IGNORECASE).sub("", short_message) # Removes incomplete HTML
return short_message
-def cut_home_msg(message, boardlength=0):
- return cut_msg(message, Settings.HOME_LASTPOSTS_LENGTH - boardlength)
-
-def getLastAge(board_type, limit):
+def getLastAge(board_type, limit, rss=False):
threads = []
- sql = "SELECT posts.id, boards.name AS board_fulln, boards.subname AS board_name, board_type, boards.dir, timestamp, bumped, last, length, thumb, 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"
- threads = FetchAll(sql, (board_type, limit))
+ 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"
+ 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"
+ threads = FetchAll(sql, (limit,) )
+
for post in threads:
- post['id'] = int(post['id'])
- post['bumped'] = int(post['bumped'])
- post['last'] = int(post['last'])
- post['length'] = int(post['length'])
- post['board_type'] = int(post['board_type'])
- post['timestamp'] = int(post['timestamp'])
- post['content'] = cut_home_msg(post['content'], 0)
+ 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'])
@@ -1042,16 +1041,12 @@ def getLastAge(board_type, limit):
def getNewThreads(limit):
threads = []
- sql = "SELECT posts.id, boards.name AS board_fulln, boards.subname AS board_name, board_type, boards.dir, timestamp, thumb, 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 <> 34 AND boards.id <> 13 AND posts.locked = 0 ORDER BY timestamp DESC LIMIT %s"
- threads = FetchAll(sql, (limit,))
+ 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"
+ threads = FetchAll(sql, (limit,) )
for post in threads:
- post['id'] = int(post['id'])
- post['board_type'] = int(post['board_type'])
- post['timestamp'] = int(post['timestamp'])
- post['timestamp_formatted'] = formatTimestamp(post['timestamp'], True)
- post['timestamp_formatted'] = post['timestamp_formatted'][:8] + ' ' + post['timestamp_formatted'][13:]
- post['content'] = cut_home_msg(post['content'], 0)
+ post['content'] = cut_msg(post['content'], Settings.HOME_LASTPOSTS_LENGTH)
+
if post['board_type'] == 1:
post['url'] = '/%s/read/%d' % (post['dir'], post['timestamp'])
else:
@@ -1067,14 +1062,17 @@ def regenerateHome():
t = datetime.datetime.now()
limit = Settings.HOME_LASTPOSTS
+ last_bbs = getLastAge(1, limit)
+ last_ib = getLastAge(0, limit)
template_values = {
'header': Settings.SITE_TITLE,
'slogan': Settings.SITE_SLOGAN,
- 'latest_news': FetchAll("SELECT `timestamp`, `message`, `timestamp_formatted` FROM `news` WHERE `type` = '2' ORDER BY `timestamp` DESC LIMIT " + str(Settings.HOME_NEWS)),
- 'latest_age_ib': getLastAge(0, limit),
- 'latest_age_bbs': getLastAge(1, limit),
+ 'latest_news': FetchAll("SELECT `timestamp`, `message`, `timestamp_formatted` FROM `news` WHERE `type` = '2' ORDER BY `timestamp` DESC LIMIT %s", (Settings.HOME_NEWS,) ),
+ 'latest_age_bbs': last_bbs,
+ 'latest_age_ib': last_ib,
'latest_age_num': limit,
'new_threads': getNewThreads(Settings.HOME_NEWTHREADS),
+ 'rss_enabled': Settings.ENABLE_RSS,
}
page_rendered = renderTemplate('home.html', template_values)
@@ -1085,9 +1083,7 @@ def regenerateHome():
f.close()
if Settings.ENABLE_RSS:
- sql = "SELECT id, boardid, board_name, timestamp, timestamp_formatted, content, url FROM last ORDER BY timestamp DESC LIMIT 10"
- rss = FetchAll(sql)
- rss_rendered = renderTemplate('home.rss', {'posts': rss})
+ rss_rendered = renderTemplate('home.rss', {'posts': getLastAge(-1, 10, True)} )
f = open(Settings.HOME_DIR + "bai.rss", "w")
try:
f.write(rss_rendered)
@@ -1221,39 +1217,13 @@ def make_redirect(url, timetaken=None):
return renderTemplate('redirect.html', {'url': url, 'message': randomPhrase, 'timetaken': timetaken})
-def latestAdd(post, postnum, postid, parent_post):
- board = Settings._.BOARD
-
- #UpdateDb("DELETE FROM last LIMIT 15, 500#")
-
- if post['subject'] and post['subject'] != board["subject"]:
- content = post['subject']
- else:
- content = cut_home_msg(post['message'], len(board['name']))
-
- timestamp_formatted = datetime.datetime.fromtimestamp(post['timestamp']).strftime('%Y-%m-%dT%H:%M:%S%Z')
- parentid = parent_post['id'] if post['parentid'] else postid
-
- if board['board_type'] == 1:
- url = '/%s/read/%s/%d' % (board['dir'], (parent_post['timestamp'] if post['parentid'] else post['timestamp']), (postnum if postnum else 1))
- else:
- url = '/%s/res/%s.html#%s' % (board['dir'], parentid, postid)
-
- sql = "INSERT INTO last (id, boardid, board_name, timestamp, timestamp_formatted, content, url) VALUES (%s, %s, %s, %s, %s, %s, %s)"
- params = (postid, board['id'], board['name'], post['timestamp'], timestamp_formatted, content, url)
- UpdateDb(sql, params)
-
-def latestRemove(postid):
- board = Settings._.BOARD
- UpdateDb("DELETE FROM last WHERE id = %s AND boardid = %s", (postid, board['id']))
-
def archiveThread(postid):
import json
board = Settings._.BOARD
thread = getThread(postid, False)
- post_preview = cut_home_msg(thread['posts'][0]['message'], 0)
-
+ post_preview = cut_msg(thread['posts'][0]['message'], Settings.HOME_LASTPOSTS_LENGTH)
+
page = renderTemplate("txt_archive.html", {"threads": [thread], "replythread": postid, "preview": post_preview}, False)
with open(Settings.ROOT_DIR + board["dir"] + "/kako/" + str(thread['timestamp']) + ".html", "w") as f:
f.write(page)
@@ -1266,8 +1236,7 @@ def archiveThread(postid):
except:
raise UserError("Can't archive: %s" % thread['timestamp'])
- UpdateDb("REPLACE INTO archive (oldid, boardid, timestamp, subject, length) VALUES (%s, %s, %s, %s, %s)",
- (thread['id'], board['id'], thread['timestamp'], thread['subject'], thread['length']))
+ UpdateDb("REPLACE INTO archive (oldid, boardid, timestamp, subject, length) VALUES (%s, %s, %s, %s, %s)", (thread['id'], board['id'], thread['timestamp'], thread['subject'], thread['length']))
def discord_hook(post, parent_post, url):
if not Settings.DISCORD_HOOK_URL:
diff --git a/cgi/templates/home.rss b/cgi/templates/home.rss
index dc69377..d293861 100644
--- a/cgi/templates/home.rss
+++ b/cgi/templates/home.rss
@@ -15,10 +15,10 @@
</image>
<?py for post in posts: ?>
<item>
- <title>${post['board_name']}: #{post['content']}</title>
+ <title>${post['board_fulln']}: #{post['content']}</title>
<pubDate>${post['timestamp_formatted']}</pubDate>
<link>https://bienvenidoainternet.org#{post['url']}</link>
</item>
<?py #endfor ?>
</channel>
-</rss> \ No newline at end of file
+</rss>
diff --git a/cgi/weabot.py b/cgi/weabot.py
index 85656d2..9a61acb 100755
--- a/cgi/weabot.py
+++ b/cgi/weabot.py
@@ -244,8 +244,7 @@ class weabot(object):
content = content.replace('.html', '')
threads['url'] = content
caught = True
- self.output = renderTemplate(
- 'latest.html', {'latest_age_ib': latest_age_ib, 'latest_age_bbs': latest_age_bbs}, True)
+ self.output = renderTemplate('latest.html', {'latest_age_ib': latest_age_ib, 'latest_age_bbs': latest_age_bbs}, True)
elif path_split[1] == "mobilenewest":
OpenDb()
newthreads = getNewThreads(Settings.HOME_LASTPOSTS)
@@ -848,13 +847,9 @@ class weabot(object):
post_url = make_url(postid, post, parent_post or post, noko, mobile)
if not board['secret']:
- # add to recent posts
- if Settings.ENABLE_RSS:
- latestAdd(post, thread_length, postid, parent_post)
# call discord hook
if Settings.ENABLE_DISCORD_HOOK:
- hook_url = make_url(
- postid, post, parent_post or post, True, False)
+ hook_url = make_url(postid, post, parent_post or post, True, False)
discord_hook(post, parent_post, hook_url)
return (post_url, ttaken, postid)
@@ -895,7 +890,6 @@ class weabot(object):
deltype = 1
deletePost(to_delete[0], password, deltype, imageonly)
- latestRemove(post['id'])
regenerateHome()
else:
# delete all checked posts (IB)
@@ -906,7 +900,6 @@ class weabot(object):
for pid in to_delete:
try:
deletePost(pid, password, board['recyclebin'], imageonly)
- latestRemove(pid)
deleted += 1
msgs.append('No.%d: Eliminado' % pid)
except UserError as message: