Skip to content

Instantly share code, notes, and snippets.

@MikeRixWolfe
Created December 9, 2023 05:47
Show Gist options
  • Save MikeRixWolfe/166c314809a13252a2929e7d8eef9118 to your computer and use it in GitHub Desktop.
Save MikeRixWolfe/166c314809a13252a2929e7d8eef9118 to your computer and use it in GitHub Desktop.
Check which automod regex flagged a post
import config
import re
import sys
from praw import Reddit
from prawcore import exceptions
args = ' '.join(sys.argv[1:]).strip()
if len(args) != 7:
print("Not a valid ID")
sys.exit()
regex_list = []
r = Reddit(user_agent='Python PRAW script by /u/' + config.reddit_username,
client_id=config.reddit_client_id, client_secret=config.reddit_client_secret,
username=config.reddit_username, password=config.reddit_password)
post = r.submission(id=args)
try:
for part, string in {"Title": post.title, "Body": post.selftext}.items():
for r in regex_list:
try:
found = re.search(r, string, re.I)
if found:
print(f"{part} match found\nRule: {r}\nMatch: {found.group(0)}\n")
except Exception as e:
print(f"Issue with {r}")
print(e)
except exceptions.NotFound:
print("Post not found")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment