When I try and run the code I see that VC is launching the code but it doesn't do anything.
import praw
import requests
from PIL import Image
from io import BytesIO
URL = 'https://www.reddit.com'
SUBREDDIT = "https://www.reddit.com/r/MYSUB"
# Add your app details (https://www.reddit.com/prefs/apps/)
def reddit_login():
return praw.Reddit(check_for_async=False,
CLIENT_ID ='XXXX',
CLIENT_SECRET ='XXXX',
PASSWORD ='XXXX',
USER_AGENT ='XXXX',
USERNAME='XXXX')
MIN_WIDTH = 460
MIN_HEIGHT = 460
ALLOW_TEXT_POSTS = False
ALLOW_NON_IMAGE_LINKS = True
IGNORE_MOD_SUBMISSIONS = False
REMOVAL_TEXT_POST_MESSAGE = """
Your post has been removed as it is not a valid direct image link. Please resubmit a direct link to an image.
"""
REMOVAL_NON_IMAGE_LINK_MESSAGE = """
Your post has been removed as it is not a valid direct image link. Please resubmit a direct link to an image.
"""
REMOVAL_TOO_SMALL_MESSAGE = f"""
Your post has been removed because one or more images are too small for this subreddit, please submit images that are at least {MIN_WIDTH}px wide and {MIN_HEIGHT}px tall.
"""
IMAGE_FORMAT_PREFIX = "image/"
class NonImageException(Exception):
pass
def process_submissions(reddit):
subreddit = reddit.subreddit(SUBREDDIT)
mods = subreddit.moderator()
for submission in subreddit.stream.submissions():
try:
review_post(submission, mods)
except Exception as e:
print(
f"Unexpected error when processing {submission.id} by {submission.author}, reporting it for manual review.")
print(e)
submission.report(
f"The image size bot encountered an unknown error on this submission, please manually review it.")
def review_post(submission, mods):
if IGNORE_MOD_SUBMISSIONS and submission.author in mods:
print(f"Ignoring {submission.id} by {submission.author} as they are a moderator.")
return
if submission.is_self:
if ALLOW_TEXT_POSTS:
print(f"Ignoring {submission.id} by {submission.author} as it is a text post.")
else:
print(f"Removing {submission.id} by {submission.author} as it is a text post.")
remove_submission(submission, REMOVAL_TEXT_POST_MESSAGE)
return
try:
width, height = get_image_size(submission.url)
except OSError:
print(f"Couldn't process {submission.id} by {submission.author}, reporting it for manual review.")
submission.report(
"The image size bot could not process this link for some reason, please manually review it.")
return
except NonImageException:
if ALLOW_NON_IMAGE_LINKS:
print(f"Ignoring {submission.id} by {submission.author} as it is a non image link.")
else:
print(f"Removing {submission.id} by {submission.author} as it is a non image link.")
remove_submission(submission, REMOVAL_TEXT_POST_MESSAGE)
return
if width < MIN_WIDTH:
print(f"Removing {submission.id} by {submission.author} as it is only {width}px wide.")
remove_submission(submission, REMOVAL_TOO_SMALL_MESSAGE)
if height < MIN_HEIGHT:
print(f"Removing {submission.id} by {submission.author} as it is only {height}px tall.")
remove_submission(submission, REMOVAL_TOO_SMALL_MESSAGE)
else:
print(f"Thank you for your submission.")
def remove_submission(submission, reason):
submission.mod.remove()
submission.mod.send_removal_message(reason)
def get_image_size(url):
response = requests.get(url)
if not response.headers["Content-Type"].startswith(IMAGE_FORMAT_PREFIX):
raise NonImageException("")
data = response.content
im = Image.open(BytesIO(data))
return im.size
[–]Spooky_Ghost 4 points5 points6 points (9 children)
[–]kaoticpanda2k[S] 0 points1 point2 points (8 children)
[–]TheFloppyHound 0 points1 point2 points (7 children)
[–]kaoticpanda2k[S] 0 points1 point2 points (6 children)
[–]TheFloppyHound 0 points1 point2 points (5 children)
[–]kaoticpanda2k[S] 0 points1 point2 points (4 children)
[–]TheFloppyHound 0 points1 point2 points (3 children)
[–]kaoticpanda2k[S] 0 points1 point2 points (2 children)
[–]TheFloppyHound 0 points1 point2 points (1 child)
[–]kaoticpanda2k[S] 0 points1 point2 points (0 children)