From 966aee5659764997957a7f2c4f4303f4d60bec88 Mon Sep 17 00:00:00 2001 From: lifegpc Date: Tue, 19 Jan 2021 19:32:02 +0800 Subject: [PATCH] update the way to calculate update interval --- rssbot.py | 12 ++++++++---- rsslist.py | 12 +++++++++--- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/rssbot.py b/rssbot.py index 3ed579e..a797dc5 100644 --- a/rssbot.py +++ b/rssbot.py @@ -1057,7 +1057,8 @@ class callbackQueryHandle(Thread): rssList = self._main._db.getRSSListByChatId(chatId) ind = int(self._inputList[3]) ind = max(min(ind, len(rssList)), 0) - di['text'] = getTextContentForRSSInList(rssList[ind]) + di['text'] = getTextContentForRSSInList( + rssList[ind], self._main._setting) di['parse_mode'] = 'HTML' di['reply_markup'] = getInlineKeyBoardForRSSInList( chatId, rssList[ind], ind, self._main._setting._botOwnerList.isOwner(self._fromUserId)) @@ -1117,7 +1118,8 @@ class callbackQueryHandle(Thread): rssList = self._main._db.getRSSListByChatId(chatId) ind = int(self._inputList[3]) ind = max(min(ind, len(rssList)), 0) - di['text'] = getTextContentForRSSInList(rssList[ind]) + di['text'] = getTextContentForRSSInList( + rssList[ind], self._main._setting) di['parse_mode'] = 'HTML' di['reply_markup'] = getInlineKeyBoardForRSSSettingsInList( chatId, rssList[ind], ind) @@ -1150,7 +1152,8 @@ class callbackQueryHandle(Thread): self.answer('修改设置失败') rssList = self._main._db.getRSSListByChatId(chatId) ind = max(min(ind, len(rssList)), 0) - di['text'] = getTextContentForRSSInList(rssList[ind]) + di['text'] = getTextContentForRSSInList( + rssList[ind], self._main._setting) di['parse_mode'] = 'HTML' di['reply_markup'] = getInlineKeyBoardForRSSSettingsInList( chatId, rssList[ind], ind) @@ -1169,7 +1172,8 @@ class callbackQueryHandle(Thread): rssList = self._main._db.getRSSListByChatId(chatId) ind = int(self._inputList[3]) ind = max(min(ind, len(rssList)), 0) - di['text'] = getTextContentForRSSInList(rssList[ind]) + di['text'] = getTextContentForRSSInList( + rssList[ind], self._main._setting) di['parse_mode'] = 'HTML' di['reply_markup'] = getInlineKeyBoardForRSSInList( chatId, rssList[ind], ind, self._main._setting._botOwnerList.isOwner(self._fromUserId)) diff --git a/rsslist.py b/rsslist.py index 6459420..249087a 100644 --- a/rsslist.py +++ b/rsslist.py @@ -18,7 +18,7 @@ from typing import List from enum import Enum, unique from math import ceil, floor from textc import textc, timeToStr -from botOwner import BotOwnerList +from readset import settings @unique @@ -43,11 +43,17 @@ class InlineKeyBoardForRSSList(Enum): ForceUpdate = 17 -def getTextContentForRSSInList(rssEntry: RSSEntry) -> str: +def getTextContentForRSSInList(rssEntry: RSSEntry, s: settings) -> str: text = textc() text.addtotext( f"""{rssEntry.title}""") - temp = '更新间隔:未知' if rssEntry.interval is None else f'更新间隔:{rssEntry.interval}分' + temp = '' + if rssEntry.lasterrortime >= rssEntry.lastupdatetime and rssEntry.errorcount > 0: + temp = f'更新间隔:{s._retryTTL[rssEntry.errorcount]}' + else: + ttl = 0 if rssEntry.interval is None else rssEntry.interval + ttl = max(min(ttl, s._maxTTL), s._minTTL) + temp = f'更新间隔:{ttl}' text.addtotext(temp) temp = '上次更新时间:未知' if rssEntry.lastupdatetime is None or rssEntry.lastupdatetime < 0 else f'上次更新时间:{timeToStr(rssEntry.lastupdatetime)}' text.addtotext(temp)