Click here to Skip to main content
15,849,494 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
import requests
import re

# Replace with the path to the text file

file_path = r'C:\'

# Replace with your webhook URL
webhook_url = 'https://discord.com'

# Create a set to store seen messages
seen_messages = set()

# Keep reading and sending the last line of the file
while True:
    try:
        # Read the last line of the file
        with open(file_path, 'rb') as f:
            f.seek(-2, 2)
            while f.read(1) != b'\n':
                f.seek(-2, 1)
            last_line = f.readline().decode()

        # Check if the last line contains [CLAN] and deposited, and doesn't contain vehiculul
        if 'Newbie' in last_line or 'Advanced' in last_line or 'Veteran' in last_line or 'Legend' in last_line or 'Inviter' in last_line or 'The Sentinel' in last_line or 'The King' in last_line or 'deposited' in last_line:
            # Use regular expressions to remove hex codes in the format {FF0000} from the last line
            formatted_line = re.sub(r'\{([0-9A-Fa-f]{6})\}', '', last_line)
            formatted_line = re.sub(r'\[CLAN\]', '', formatted_line)
            formatted_line = re.sub(r']', ' ', formatted_line)
            formatted_line = re.sub(r'\[', '', formatted_line)
            formatted_line = re.sub(r'»', '', formatted_line)

            # Check if the message has been seen before
            if formatted_line not in seen_messages:
                # Add the message to the set of seen messages
                seen_messages.add(formatted_line)

                # Send the message to the Discord webhook
                requests.post(webhook_url, data={'content': formatted_line})
    except:
        # Ignore any errors and continue
        pass


What I have tried:

this is the code.

I try to use only that lines that are using the exact word. example Legend has kicked the ball- to be used because contains the word 'Legend' Legendary has kicked the ball- not to use because don't contain the exact word 'Legend'
Posted
Updated 12-Dec-22 22:46pm

1 solution

Easiest is probably to use Regular Expressions

Reference is here : re — Regular expression operations — Python 3.11.1 documentation[^]
A two part article with examples : Regular Expressions: Regexes in Python (Part 1) – Real Python[^]
A blog about matching exact words: How to Match an Exact Word in Python Regex? (Answer: Don’t) – Finxter[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900