Advertisement
Guest User

Untitled

a guest
Feb 1st, 2025
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. import os
  2. import requests
  3.  
  4. file_path = "C:\\path\\to\\your\\file.txt"
  5. webhook_url = "YOUR_DISCORD_WEBHOOK_URL"
  6. last_position_file = "last_position.txt"
  7.  
  8. def send_to_discord(message):
  9. """Send a message to the Discord webhook."""
  10. payload = {"content": message}
  11. response = requests.post(webhook_url, json=payload)
  12. if response.status_code != 204:
  13. print(f"Failed to send message: {response.status_code}, {response.text}")
  14.  
  15. def read_new_lines(file_path):
  16. """Reads new lines from the file since the last read position."""
  17. last_pos = 0
  18. if os.path.exists(last_position_file):
  19. with open(last_position_file, "r") as f:
  20. last_pos = int(f.read().strip() or 0)
  21.  
  22. new_lines = []
  23. with open(file_path, "r", encoding="utf-8") as f:
  24. f.seek(last_pos)
  25. new_lines = f.readlines()
  26. last_pos = f.tell()
  27.  
  28. # Store the updated position
  29. with open(last_position_file, "w") as f:
  30. f.write(str(last_pos))
  31.  
  32. return [line.strip() for line in new_lines if line.strip()]
  33.  
  34. def process_file_updates():
  35. """Reads new lines and sends them to Discord."""
  36. new_lines = read_new_lines(file_path)
  37.  
  38. if new_lines:
  39. for line in new_lines:
  40. send_to_discord(line)
  41. else:
  42. print("No new entries found.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement