Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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']
Expand All @@ -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]
Expand Down
35 changes: 12 additions & 23 deletions modlog_wiki_publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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")

Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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],
)

Expand Down
7 changes: 3 additions & 4 deletions tests/test_removal_reasons.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -85,8 +85,7 @@ def test_removal_reasons():
created_at INTEGER NOT NULL,
processed_at INTEGER DEFAULT (strftime('%s', 'now'))
)
"""
)
""")
conn.commit()
conn.close()

Expand Down
Loading