import os
import re
import logging
from telegram import Bot
from telegram import InputFile
from telegram import ParseMode
from telegram.error import TelegramError
from telegram.ext import Updater
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
# Replace with your own bot's token
BOT_TOKEN = os.environ.get("BOT_TOKEN")
# Replace with the chat ID of your own channel
CHANNEL_ID = int(os.environ.get("CHANNEL_ID"))
# Replace with the text you want to remove from the posts
TEXT_TO_REMOVE = "Text to remove"
def main():
bot = Bot(token=BOT_TOKEN)
updater = Updater(bot=bot, use_context=True)
try:
# Get the latest post from the source channel
source_post = bot.get_chat(CHANNEL_ID).description
# Remove the specified text from the post
filtered_post = re.sub(TEXT_TO_REMOVE, "", source_post)
# Send the filtered post to your own channel
bot.send_message(chat_id=CHANNEL_ID, text=filtered_post)
except TelegramError as e:
logger.error(e)
if __name__ == '__main__':
main()