Files
ObsidianAI/watch_changes.py

35 lines
959 B
Python

import couchdb
import time
import json
from urllib.parse import quote
# Configuration
user = "admin"
password = "DonCucarach0!?"
ip_address = "100.100.112.48"
port = "5984"
db_name = "obsidiandb"
safe_password = quote(password, safe="")
url = f"http://{user}:{safe_password}@{ip_address}:{port}/"
print("Listening for changes on CouchDB...")
server = couchdb.Server(url)
db = server[db_name]
# Get current update sequence
since = db.info()['update_seq']
print(f"Current Seq: {since}")
# Poll for changes
while True:
changes = db.changes(since=since, feed='longpoll', timeout=10000)
since = changes['last_seq']
for change in changes['results']:
print(f"Change detected! ID: {change['id']}, Deleted: {change.get('deleted', False)}")
# Check if it's one of our moved files
if "05 - fleeting" in change['id'].lower() or "science" in change['id'].lower():
print(" -> RELEVANT FILE CHANGED")
time.sleep(1)