fix(server): Fix bug in time comparison logic in RedditGetPostsBlock (#7426)
Co-authored-by: Zamil Majdy <zamil.majdy@agpt.co>pull/7427/head^2
parent
e70e613f73
commit
03ea4c2690
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue