import time
import feedparser
import telebot
import logging
TOKEN = 'Tokaev'
CHANNEL_ID = '-100'
NEWS_FILE_PATH = 'news.txt'
URLC = 'https://t.me/'
CLM = "Channel Name"
bot = telebot.TeleBot(TOKEN)
sent_news = set()
def send_news(news_title, channel_name, article_link):
try:
caption = f"{news_title}\n\n<a href='{URLC}'>{CLM}</a> | <a href='{article_link}'>READ</a>"
bot.send_message(CHANNEL_ID, caption, parse_mode='HTML', disable_web_page_preview=True if channel_name == URLC else False)
logging.info(f"Sent message for news: {news_title}")
with open(NEWS_FILE_PATH, 'a') as file:
file.write(news_title + '\n')
sent_news.add(news_title)
except Exception as e:
logging.error(f"Error sending message to channel: {e}")
def check_and_send_news():
try:
feed = feedparser.parse('http://example.com/external.php?type=rss2') # Replace with the URL of the XenForo RSS feed
latest_news = feed.entries[0]
news_title = latest_news.title
if news_title not in sent_news:
article_link = latest_news.link
send_news(news_title, CLM, article_link)
except Exception as e:
logging.error(f"Error checking and sending news: {e}")
logging.basicConfig(level=logging.INFO, filename='bot.log', format='%(asctime)s - %(levelname)s - %(message)s')
while True:
try:
check_and_send_news()
time.sleep(300)
except KeyboardInterrupt:
break
except Exception as e:
logging.error(f"Error: {e}")