diff --git a/app.py b/app.py index 018aebf..d3645d3 100755 --- a/app.py +++ b/app.py @@ -533,7 +533,7 @@ class Irc_bot: print(f'''Feed {url} non accepted category {category} on line {str(line_count)}''') else: print(f'Feed {url} already added: line {str(line_count)}') - print(f'Feeds loaded: {str(feed_count)}') + return f'Feeds loaded: {str(feed_count)}' get_feed_list(self) @@ -617,24 +617,24 @@ class Irc_bot: if 'terminus_answer' in latest_article: post_number_list = latest_article.terminus_answer.split(' ') post_number = post_number_list[len(post_number_list)-1] - terminus_answer = f' reply to #{post_number} ' + terminus_answer = f'reply to >{post_number}' else: post_number = '' terminus_answer = 'new post' if 'terminus_timestamp' in latest_article: - terminus_timestamp = f' at {latest_article.terminus_timestamp} ' + terminus_timestamp = f' at {latest_article.terminus_timestamp}' else: terminus_timestamp = '' if 'terminus_author' in latest_article: - terminus_author = f' by {latest_article.terminus_author} ' + terminus_author = f' by {latest_article.terminus_author}' else: - terminus_author = ' anon ' + terminus_author = ' anon' def strip_bbcode(msg, post_number): max_chars = 200 s = [ - ']', '[b', '[i', '[li', '[s', '[sp', '[h', '[u', '[url', '[wiki', '[t', '[find', '"', '\n', '>', '>>' + '[find', '[li', '[sp', '[url', '[wiki', '[u', '[t', '[s', '[h', '[b', '[i', ']', '"', '\n', '>>', '>', ] - if len(post_number) != 0: + if len(post_number) > 0: s.append(post_number) for i in s: msg = msg.replace(i, '') @@ -643,7 +643,7 @@ class Irc_bot: msg = f'{msg[:max_chars]}...' return msg description = strip_bbcode(latest_article.description, post_number) - title = f'/s {latest_article.terminus_sub}{terminus_timestamp}{terminus_answer}{terminus_author} {description}' + title = f'/s {latest_article.terminus_sub}{terminus_timestamp} {terminus_answer}{terminus_author} {description}' return title async def get_feed( @@ -746,7 +746,7 @@ class Irc_bot: msg_description = f'{msg_description[:50]}...' msg_url = (self.feed_dict[url])['link'][i] col = self.color_dict[feed_url[url]['category']] - the_host = get_host(msg_url) + the_host = get_short_url(msg_url) # if the_host in switch_urls: # # url_q = msg_url.split(shorten)[1] # url_q = msg_url.replace(the_host, shorten) @@ -830,16 +830,32 @@ class Irc_bot: def irc_rss_feed_control(exit_event, self): print(f'Starting RSS feed bot') proxy_url = f'http://{self.hostname}:{self.http_tunnel}' - feed_list_test = [] + feed_list_long = [] + feed_list_short = [] + waited_time = 0 + for k, v in feed_url.items(): + if v['category'] == 'news' or v['category'] == 'torrents': + feed_list_short.append(k) for item in feed_url: - feed_list_test.append(item) + feed_list_long.append(item) while not exit_event.is_set(): + if waited_time >= self.rss_feed_update: + waited_time = 0 + long = True + else: + long = False self.feed_count = 0 - htmls = asyncio.run(gather_feeds(self, feed_list_test, proxy_url)) + if self.first_run or long: + feeds_to_use = feed_list_long + else: + feeds_to_use = feed_list_short + htmls = asyncio.run(gather_feeds(self, feeds_to_use, proxy_url)) if self.first_run == True: print(f"Finished updating {str(len(self.feed_dict))} feeds.") self.first_run = False - time.sleep(self.rss_feed_update) + time.sleep(600) + waited_time += 600 + # time.sleep(self.rss_feed_update) def send_throttle(exit_event, self): start = True while not exit_event.is_set(): @@ -1216,8 +1232,9 @@ class Irc_bot: elif 'refresh' in line[4]: do_command = False - get_feed_list(self) - msg.append(f"{admin_user} {com_msg} refreshing feed list.") + loaded = get_feed_list(self) + msg.append(f"{admin_user} {com_msg} {loaded}") + # msg.append(f"{admin_user} {com_msg} refreshing feed list.") # command = [f'PRIVMSG {line[5]} {reason}'] elif 'throttle' in line[4]: reason, reason_msg = remaining_msg_irc(line, 4, False, False) diff --git a/changelognewsbot.txt b/changelognewsbot.txt index 9008706..e0e4617 100755 --- a/changelognewsbot.txt +++ b/changelognewsbot.txt @@ -1,4 +1,4 @@ -19/9/2025: added better parsing for terminus.i2p and rss feeds from gitea, separate "clean" channel (no torrents) +19/09/2025: added better parsing for terminus.i2p and rss feeds from gitea, separate "clean" channel (no torrents) 18/09/2025: added 25 new rss feeds, removed some dead ones 28/03/2025: added rss feeds from git.simp.i2p along with other new feeds, fixed another bug with html code showing up correctly, updated footer 21/01/2025: Improvements in parsing urls and html tags