Skip to content

Instantly share code, notes, and snippets.

@fnx4
Created December 25, 2021 18:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save fnx4/9c70ee2969babaf6b931836e62390b13 to your computer and use it in GitHub Desktop.
Save fnx4/9c70ee2969babaf6b931836e62390b13 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