def rss_set(context: CallbackContext): user_data = sql.get_all() bot, job = context.bot, context.job # this loop checks for every row in the DB for row in user_data: row_id = row.id tg_feed_link = row.feed_link tg_old_entry_link = row.old_entry_link feed_processed = parse(tg_feed_link) new_entry_links = [] new_entry_titles = [] # this loop checks for every entry from the RSS Feed link from the DB row for entry in feed_processed.entries: # check if there are any new updates to the RSS Feed from the old entry if entry.link != tg_old_entry_link: new_entry_links.append(entry.link) new_entry_titles.append(entry.title) else: break # check if there's any new entries queued from the last check if new_entry_links: sql.update_url(row_id, new_entry_links) else: pass
def rss_update(context: CallbackContext): user_data = sql.get_all() job = context.job bot = context.bot # this loop checks for every row in the DB for row in user_data: row_id = row.id tg_chat_id = row.chat_id tg_feed_link = row.feed_link feed_processed = parse(tg_feed_link) tg_old_entry_link = row.old_entry_link new_entry_links = [] new_entry_titles = [] # this loop checks for every entry from the RSS Feed link from the DB row for entry in feed_processed.entries: # check if there are any new updates to the RSS Feed from the old entry if entry.link != tg_old_entry_link: new_entry_links.append(entry.link) new_entry_titles.append(entry.title) else: break # check if there's any new entries queued from the last check if new_entry_links: sql.update_url(row_id, new_entry_links) else: pass if len(new_entry_links) < 5: # this loop sends every new update to each user from each group based on the DB entries for link, title in zip( reversed(new_entry_links), reversed(new_entry_titles)): final_message = "<b>{}</b>\n\n{}".format( html.escape(title), html.escape(link)) if len(final_message) <= constants.MAX_MESSAGE_LENGTH: bot.send_message( chat_id=tg_chat_id, text=final_message, parse_mode=ParseMode.HTML) else: bot.send_message( chat_id=tg_chat_id, text="<b>Warning:</b> The message is too long to be sent", parse_mode=ParseMode.HTML) else: for link, title in zip( reversed(new_entry_links[-5:]), reversed(new_entry_titles[-5:])): final_message = "<b>{}</b>\n\n{}".format( html.escape(title), html.escape(link)) if len(final_message) <= constants.MAX_MESSAGE_LENGTH: bot.send_message( chat_id=tg_chat_id, text=final_message, parse_mode=ParseMode.HTML) else: bot.send_message( chat_id=tg_chat_id, text="<b>Warning:</b> The message is too long to be sent", parse_mode=ParseMode.HTML) bot.send_message( chat_id=tg_chat_id, parse_mode=ParseMode.HTML, text="<b>Warning: </b>{} occurrences have been left out to prevent spam" .format(len(new_entry_links) - 5))