Исходники - Агрегатор новостей Telegram V2 | End Way — сообщество разработчиков и готовых решений
  • Больше материалов без ожидания и лишних условий
    Доступ к скрытым публикациям на 2 месяца, 3 месяца или навсегда. Ограничения «Команда форума» и «Личный» сохраняются.

    Сравнить варианты доступа →

    🔔 EndWay в Telegram

    Следите за новостями и релизами:
    EndWay | EndSoft

Исходники Агрегатор новостей Telegram V2

GeMeOp

Бот
Автор темы
8 Авг 2023
41
261
Нашел свой старый код, решил немного переделать.
Пишите что можно добавить, возможно реализую.

 
Последнее редактирование:
  • 29
Реакции: 28 users

GeMeOp

Бот
Автор темы
8 Авг 2023
41
261
nikitas244, все новости из rss канала ria новости перекидывает в тг канал добавляя гиперссылку с названием канала и также на статью.
 

CashOutGang

Сеньор
14 Июн 2023
161
80
timbo,
To parse news from an RSS feed from a XenForo forum, you can modify the check_and_send_news() function as follows:

Python:
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}")

Here's what has changed:


  1. Replaced the feed URL with the appropriate URL of the XenForo RSS feed. It typically follows the format http://example.com/external.php?type=rss2 , but you need to replace example.com with the actual domain of your XenForo forum.

Make sure to have the feedparser library installed (pip install feedparser) to parse the RSS feed.
 

CashOutGang

Сеньор
14 Июн 2023
161
80
Python:
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}")
 
Активность:
Пока что здесь никого нет