1
0
Fork 0

Better detection of previous post

This commit is contained in:
Casper V. Kristensen 2022-05-08 14:51:01 +02:00
parent 7af94add96
commit 65ee59722a

View file

@ -1,4 +1,5 @@
import logging
import re
import praw
from praw.models import Submission
@ -23,5 +24,10 @@ def submit_post(title, text, subreddit) -> Submission:
def get_previous_daily_post(subreddit) -> Submission:
logger.info("Getting previous daily post from r/%s", subreddit)
return next(praw.subreddit(subreddit).search('title:"daily releases"', sort="new", syntax="lucene",
time_filter="week"))
posts = praw.subreddit(subreddit).search('title:"daily releases"', sort="new", syntax="lucene",
time_filter="week")
return next(
p
for p in posts
if re.search("daily release.*[(].* \d\d\d\d[)]", p.title, flags=re.IGNORECASE)
)