Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import requests
- file_path = "C:\\path\\to\\your\\file.txt"
- webhook_url = "YOUR_DISCORD_WEBHOOK_URL"
- last_position_file = "last_position.txt"
- def send_to_discord(message):
- """Send a message to the Discord webhook."""
- payload = {"content": message}
- response = requests.post(webhook_url, json=payload)
- if response.status_code != 204:
- print(f"Failed to send message: {response.status_code}, {response.text}")
- def read_new_lines(file_path):
- """Reads new lines from the file since the last read position."""
- last_pos = 0
- if os.path.exists(last_position_file):
- with open(last_position_file, "r") as f:
- last_pos = int(f.read().strip() or 0)
- new_lines = []
- with open(file_path, "r", encoding="utf-8") as f:
- f.seek(last_pos)
- new_lines = f.readlines()
- last_pos = f.tell()
- # Store the updated position
- with open(last_position_file, "w") as f:
- f.write(str(last_pos))
- return [line.strip() for line in new_lines if line.strip()]
- def process_file_updates():
- """Reads new lines and sends them to Discord."""
- new_lines = read_new_lines(file_path)
- if new_lines:
- for line in new_lines:
- send_to_discord(line)
- else:
- print("No new entries found.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement