fix(server): Fix bug in time comparison logic in RedditGetPostsBlock (#7426)

Co-authored-by: Zamil Majdy <zamil.majdy@agpt.co>
pull/7427/head^2
Toran Bruce Richards 2024-07-16 08:35:51 +01:00 committed by GitHub
parent e70e613f73
commit 03ea4c2690
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 4 deletions

View File

@ -103,11 +103,16 @@ class RedditGetPostsBlock(Block):
return subreddit.new(limit=input_data.post_limit)
def run(self, input_data: Input) -> BlockOutput:
current_time = datetime.now(tz=timezone.utc)
for post in self.get_posts(input_data):
if input_data.last_minutes and post.created_utc < datetime.now(
tz=timezone.utc) - \
timedelta(minutes=input_data.last_minutes):
break
if input_data.last_minutes:
post_datetime = datetime.fromtimestamp(
post.created_utc,
tz=timezone.utc
)
time_difference = current_time - post_datetime
if time_difference.total_seconds() / 60 > input_data.last_minutes:
continue
if input_data.last_post and post.id == input_data.last_post:
break