import sqlite3 import time import requests import os from dotenv import load_dotenv load_dotenv() WEBHOOK_URL = os.getenv("DISCORD_WEBHOOK_URL") DATABASE = "database.db" def send_to_discord(message): if not WEBHOOK_URL: print("No webhook set") return requests.post(WEBHOOK_URL, json={"content": message}) def main(): last_id = 0 if os.path.exists("last.id"): with open("last.id", "r") as f: last_id = int(f.read().strip()) while True: conn = sqlite3.connect(DATABASE) cursor = conn.cursor() cursor.execute("SELECT id, content FROM posts WHERE id > ?", (last_id,)) rows = cursor.fetchall() conn.close() for post_id, content in rows: send_to_discord(f"New praise #{post_id}: {content}") last_id = post_id with open("last.id", "w") as f: f.write(str(last_id)) time.sleep(5) if __name__ == "__main__": main()