Skip to content

Instantly share code, notes, and snippets.

@yat1ma30
Forked from fnx4/noty.py
Created November 12, 2022 14:03
Show Gist options
  • Save yat1ma30/d26c1d62bdd121fa3d3b6c17bec40f8e to your computer and use it in GitHub Desktop.
Save yat1ma30/d26c1d62bdd121fa3d3b6c17bec40f8e to your computer and use it in GitHub Desktop.
monitor windows notifications
import os
import sqlite3
import time
from bs4 import BeautifulSoup
ids = set()
user = os.environ['USERPROFILE'].replace("\\", "/")
adr = u"file:" + user + u"/AppData/Local/Microsoft/Windows/Notifications/wpndatabase.db?mode=ro"
def run():
# con = sqlite3.connect("file:C:/Users/fnx/AppData/Local/Microsoft/Windows/Notifications/wpndatabase.db?mode=ro", uri=True)
con = sqlite3.connect(adr, uri=True)
cur = con.cursor()
x = cur.execute("""
SELECT
n.id AS id,
n.type AS type,
nh.primaryid AS src,
nh.createdtime AS ctime,
nh.modifiedtime AS mtime,
n.payload as data
FROM
notification n
INNER JOIN
notificationhandler nh ON n.handlerid = nh.recordid
ORDER BY id ASC
""")
resp = x.fetchall()
for row in resp:
id = row[0]
if id not in ids:
ids.add(id)
src = row[2]
time = row[3]
data = row[5]
soup = BeautifulSoup(data, "html.parser")
print(id, src, time)
for d in soup.find_all("text"):
print("\t" + d.text)
print()
con.close()
while True:
run()
time.sleep(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment