diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2eca111..4ed049a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,6 +1,6 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v6.0.0 hooks: - id: trailing-whitespace - id: end-of-file-fixer @@ -10,27 +10,27 @@ repos: - id: debug-statements - id: check-executables-have-shebangs - - repo: https://github.com/psf/black - rev: 23.7.0 + - repo: https://github.com/psf/black-pre-commit-mirror + rev: 26.1.0 hooks: - id: black language_version: python3 args: [--line-length=180] - repo: https://github.com/pycqa/flake8 - rev: 6.0.0 + rev: 7.3.0 hooks: - id: flake8 args: ['--max-line-length=180', '--ignore=E203,W503,E231,E226,E241,E722,F401,F403,F405,F541,F811,E402'] - repo: https://github.com/pycqa/isort - rev: 5.12.0 + rev: 7.0.0 hooks: - id: isort args: [--profile=black] - repo: https://github.com/Yelp/detect-secrets - rev: v1.4.0 + rev: v1.5.0 hooks: - id: detect-secrets args: ['--baseline', '.secrets.baseline'] @@ -44,7 +44,7 @@ repos: )$ - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.4.1 + rev: v1.19.1 hooks: - id: mypy additional_dependencies: [types-requests] diff --git a/modlog_wiki_publisher.py b/modlog_wiki_publisher.py index 526ee40..77d080e 100644 --- a/modlog_wiki_publisher.py +++ b/modlog_wiki_publisher.py @@ -3,6 +3,7 @@ Reddit Modlog Wiki Publisher Scrapes moderation logs and publishes them to a subreddit wiki page """ + import argparse import hashlib import json @@ -111,12 +112,10 @@ def get_db_version(): cursor = conn.cursor() # Check if version table exists - cursor.execute( - """ + cursor.execute(""" SELECT name FROM sqlite_master WHERE type='table' AND name='schema_version' - """ - ) + """) if not cursor.fetchone(): conn.close() @@ -138,15 +137,13 @@ def set_db_version(version): conn = sqlite3.connect(DB_PATH) cursor = conn.cursor() - cursor.execute( - """ + cursor.execute(""" CREATE TABLE IF NOT EXISTS schema_version ( id INTEGER PRIMARY KEY AUTOINCREMENT, version INTEGER NOT NULL, applied_at INTEGER DEFAULT (strftime('%s', 'now')) ) - """ - ) + """) cursor.execute("INSERT INTO schema_version (version) VALUES (?)", (version,)) conn.commit() @@ -245,16 +242,14 @@ def migrate_database(): # Migration from version 0 to 1: Initial schema if current_version < 1: logger.info("Applying migration: Initial schema (v0 -> v1)") - cursor.execute( - """ + cursor.execute(""" CREATE TABLE IF NOT EXISTS processed_actions ( id INTEGER PRIMARY KEY AUTOINCREMENT, action_id TEXT UNIQUE NOT NULL, created_at INTEGER NOT NULL, processed_at INTEGER DEFAULT (strftime('%s', 'now')) ) - """ - ) + """) cursor.execute("CREATE INDEX IF NOT EXISTS idx_action_id ON processed_actions(action_id)") cursor.execute("CREATE INDEX IF NOT EXISTS idx_created_at ON processed_actions(created_at)") set_db_version(1) @@ -315,8 +310,7 @@ def migrate_database(): if current_version < 4: logger.info("Applying migration: Add wiki hash caching table (v3 -> v4)") - cursor.execute( - """ + cursor.execute(""" CREATE TABLE IF NOT EXISTS wiki_hash_cache ( id INTEGER PRIMARY KEY AUTOINCREMENT, subreddit TEXT NOT NULL, @@ -325,8 +319,7 @@ def migrate_database(): last_updated INTEGER DEFAULT (strftime('%s', 'now')), UNIQUE(subreddit, wiki_page) ) - """ - ) + """) cursor.execute("CREATE INDEX IF NOT EXISTS idx_subreddit_page ON wiki_hash_cache(subreddit, wiki_page)") logger.info("Created wiki_hash_cache table") @@ -666,12 +659,10 @@ def update_missing_subreddits(): cursor = conn.cursor() # Get entries with NULL subreddit but valid permalink - cursor.execute( - """ + cursor.execute(""" SELECT id, target_permalink FROM processed_actions WHERE subreddit IS NULL AND target_permalink IS NOT NULL - """ - ) + """) updates = [] 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 = SELECT COUNT(*) FROM processed_actions WHERE created_at >= ? AND action_type IN ({}) AND LOWER(subreddit) = LOWER(?) - """.format( - placeholders - ), + """.format(placeholders), [cutoff_timestamp] + list(wiki_actions) + [subreddit_name], ) diff --git a/tests/test_removal_reasons.py b/tests/test_removal_reasons.py index df5e2ee..5b15b8e 100644 --- a/tests/test_removal_reasons.py +++ b/tests/test_removal_reasons.py @@ -3,6 +3,7 @@ Test script to verify removal reason processing without Reddit API calls Creates a local markdown file to demonstrate the functionality """ + import os import sqlite3 import sys @@ -70,8 +71,7 @@ def test_removal_reasons(): cursor.execute("SELECT name FROM sqlite_master WHERE type='table' AND name='processed_actions'") if not cursor.fetchone(): print(" Database table not found, creating manually...") - cursor.execute( - """ + cursor.execute(""" CREATE TABLE processed_actions ( id INTEGER PRIMARY KEY AUTOINCREMENT, action_id TEXT UNIQUE NOT NULL, @@ -85,8 +85,7 @@ def test_removal_reasons(): created_at INTEGER NOT NULL, processed_at INTEGER DEFAULT (strftime('%s', 'now')) ) - """ - ) + """) conn.commit() conn.close()