def updateRSS(self, title: str, url: str, lastupdatetime: int, hashEntries: HashEntries, ttl: int = None): with self._value_lock: try: hashd = sha256WithBase64(url) cur = self._db.execute( f'SELECT * FROM RSSList WHERE id="{hashd}"') has_data = False for i in cur: # pylint: disable=unused-variable has_data = True break if not has_data: return False self._db.execute( f"UPDATE RSSList SET title='{dealtext(title)}', interval={ttl if ttl is not None else 'null'}, lastupdatetime={lastupdatetime}, errorcount=0 WHERE id='{hashd}'") cur = self._db.execute( f"SELECT * FROM hashList WHERE id='{hashd}'") has_data2 = False for i in cur: has_data2 = True break if has_data2: self._db.execute( f"DELETE FROM hashList WHERE id='{hashd}'") for v in hashEntries.getList(): self._db.execute( f"INSERT INTO hashList VALUES ('{v.id}', '{v.hash}', {v.time})") self._db.commit() return True except: return False
def calHash(url: dict, item: dict) -> HashEntry: hashd = sha256WithBase64(url) hasht = url if 'title' in item and item['title'] is not None: hasht = hasht + item['title'] if 'link' in item and item['link'] is not None: hasht = hasht + item['link'] matched = False if 'published' in item and item['published'] is not None: hasht = hasht + item['published'] matched = True if 'updated' in item and item['updated'] is not None: hasht = hasht + item['updated'] matched = True if 'pubDate' in item and item['pubDate'] is not None: hasht = hasht + item['pubDate'] matched = True if not matched and 'description' in item and item[ 'description'] is not None: hasht = hasht + item['description'] hashed = sha256WithBase64(hasht) return HashEntry(id=hashd, hash=hashed)
def setRSSForceUpdate(self, url: str, forceupdate: bool) -> bool: with self._value_lock: try: hashd = sha256WithBase64(url) cur = self._db.execute( f'SELECT * FROM RSSList WHERE id="{hashd}"') has_data = False for i in cur: # pylint: disable=unused-variable has_data = True break if not has_data: return False self._db.execute( f"UPDATE RSSList SET forceupdate={'true' if forceupdate else 'false'} WHERE id='{hashd}'") self._db.commit() return True except: return False
def addRSSList(self, title: str, url: str, chatId: int, config: RSSConfig, ttl: int = None, hashEntries: HashEntries = None): with self._value_lock: try: hashd = sha256WithBase64(url) cur = self._db.execute( f'SELECT * FROM RSSList WHERE id="{hashd}"') has_data = False for i in cur: # pylint: disable=unused-variable has_data = True break if has_data: self._db.execute( f"UPDATE RSSList SET title='{dealtext(title)}', interval={ttl if ttl is not None else 'null'} WHERE id='{hashd}'") else: self._db.execute( f"INSERT INTO RSSList VALUES ('{dealtext(title)}', '{dealtext(url)}', {ttl if ttl is not None else 'null'}, {int(time())}, '{hashd}', null, false, 0)") cur = self._db.execute( f'SELECT * FROM chatList WHERE id="{hashd}" AND chatId={chatId}') has_data2 = False for i in cur: has_data2 = True break if has_data2: self._db.execute( f'DELETE FROM chatList WHERE id="{hashd}" AND chatId={chatId}') self._db.execute( f"INSERT INTO chatList VALUES ({chatId}, '{hashd}', '{dealtext(config.toJson())}')") if hashEntries is not None and not has_data: cur = self._db.execute( f"SELECT * FROM hashList WHERE id='{hashd}'") has_data3 = False for i in cur: has_data3 = True break if has_data3: self._db.execute( f"DELETE FROM hashList WHERE id='{hashd}'") for v in hashEntries.getList(): self._db.execute( f"INSERT INTO hashList VALUES ('{v.id}', '{v.hash}', {v.time})") self._db.commit() return True except: return False
def updateRSSWithError(self, url: str, lasterrortime: int): with self._value_lock: try: hashd = sha256WithBase64(url) cur = self._db.execute( f'SELECT * FROM RSSList WHERE id="{hashd}"') has_data = False for i in cur: rss = RSSEntry(i, self._main._setting._maxCount) has_data = True break if not has_data: return False self._db.execute( f"UPDATE RSSList SET lasterrortime={lasterrortime}, errorcount={rss.errorcount + 1} WHERE id='{hashd}'") self._db.commit() return True except: return False