Skip to content

Commit 6f420bc

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 943e285 commit 6f420bc

2 files changed

Lines changed: 15 additions & 27 deletions

File tree

modlog_wiki_publisher.py

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Reddit Modlog Wiki Publisher
44
Scrapes moderation logs and publishes them to a subreddit wiki page
55
"""
6+
67
import argparse
78
import hashlib
89
import 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

tests/test_removal_reasons.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
Test script to verify removal reason processing without Reddit API calls
44
Creates a local markdown file to demonstrate the functionality
55
"""
6+
67
import os
78
import sqlite3
89
import sys
@@ -70,8 +71,7 @@ def test_removal_reasons():
7071
cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='processed_actions'")
7172
if not cursor.fetchone():
7273
print(" Database table not found, creating manually...")
73-
cursor.execute(
74-
"""
74+
cursor.execute("""
7575
CREATE TABLE processed_actions (
7676
id INTEGER PRIMARY KEY AUTOINCREMENT,
7777
action_id TEXT UNIQUE NOT NULL,
@@ -85,8 +85,7 @@ def test_removal_reasons():
8585
created_at INTEGER NOT NULL,
8686
processed_at INTEGER DEFAULT (strftime('%s', 'now'))
8787
)
88-
"""
89-
)
88+
""")
9089
conn.commit()
9190
conn.close()
9291

0 commit comments

Comments
 (0)