33Reddit Modlog Wiki Publisher
44Scrapes moderation logs and publishes them to a subreddit wiki page
55"""
6+
67import argparse
78import hashlib
89import json
@@ -111,12 +112,10 @@ def get_db_version():
111112 cursor = conn .cursor ()
112113
113114 # Check if version table exists
114- cursor .execute (
115- """
115+ cursor .execute ("""
116116 SELECT name FROM sqlite_master
117117 WHERE type='table' AND name='schema_version'
118- """
119- )
118+ """ )
120119
121120 if not cursor .fetchone ():
122121 conn .close ()
@@ -138,15 +137,13 @@ def set_db_version(version):
138137 conn = sqlite3 .connect (DB_PATH )
139138 cursor = conn .cursor ()
140139
141- cursor .execute (
142- """
140+ cursor .execute ("""
143141 CREATE TABLE IF NOT EXISTS schema_version (
144142 id INTEGER PRIMARY KEY AUTOINCREMENT,
145143 version INTEGER NOT NULL,
146144 applied_at INTEGER DEFAULT (strftime('%s', 'now'))
147145 )
148- """
149- )
146+ """ )
150147
151148 cursor .execute ("INSERT INTO schema_version (version) VALUES (?)" , (version ,))
152149 conn .commit ()
@@ -245,16 +242,14 @@ def migrate_database():
245242 # Migration from version 0 to 1: Initial schema
246243 if current_version < 1 :
247244 logger .info ("Applying migration: Initial schema (v0 -> v1)" )
248- cursor .execute (
249- """
245+ cursor .execute ("""
250246 CREATE TABLE IF NOT EXISTS processed_actions (
251247 id INTEGER PRIMARY KEY AUTOINCREMENT,
252248 action_id TEXT UNIQUE NOT NULL,
253249 created_at INTEGER NOT NULL,
254250 processed_at INTEGER DEFAULT (strftime('%s', 'now'))
255251 )
256- """
257- )
252+ """ )
258253 cursor .execute ("CREATE INDEX IF NOT EXISTS idx_action_id ON processed_actions(action_id)" )
259254 cursor .execute ("CREATE INDEX IF NOT EXISTS idx_created_at ON processed_actions(created_at)" )
260255 set_db_version (1 )
@@ -315,8 +310,7 @@ def migrate_database():
315310 if current_version < 4 :
316311 logger .info ("Applying migration: Add wiki hash caching table (v3 -> v4)" )
317312
318- cursor .execute (
319- """
313+ cursor .execute ("""
320314 CREATE TABLE IF NOT EXISTS wiki_hash_cache (
321315 id INTEGER PRIMARY KEY AUTOINCREMENT,
322316 subreddit TEXT NOT NULL,
@@ -325,8 +319,7 @@ def migrate_database():
325319 last_updated INTEGER DEFAULT (strftime('%s', 'now')),
326320 UNIQUE(subreddit, wiki_page)
327321 )
328- """
329- )
322+ """ )
330323 cursor .execute ("CREATE INDEX IF NOT EXISTS idx_subreddit_page ON wiki_hash_cache(subreddit, wiki_page)" )
331324 logger .info ("Created wiki_hash_cache table" )
332325
@@ -666,12 +659,10 @@ def update_missing_subreddits():
666659 cursor = conn .cursor ()
667660
668661 # Get entries with NULL subreddit but valid permalink
669- cursor .execute (
670- """
662+ cursor .execute ("""
671663 SELECT id, target_permalink FROM processed_actions
672664 WHERE subreddit IS NULL AND target_permalink IS NOT NULL
673- """
674- )
665+ """ )
675666
676667 updates = []
677668 for row_id , permalink in cursor .fetchall ():
@@ -751,9 +742,7 @@ def get_recent_actions_from_db(config: Dict[str, Any], force_all_actions: bool =
751742 SELECT COUNT(*) FROM processed_actions
752743 WHERE created_at >= ? AND action_type IN ({})
753744 AND LOWER(subreddit) = LOWER(?)
754- """ .format (
755- placeholders
756- ),
745+ """ .format (placeholders ),
757746 [cutoff_timestamp ] + list (wiki_actions ) + [subreddit_name ],
758747 )
759748
0 commit comments