In this video, we will write a script which goes through the posts over the last two days in a somber
edit of and the script looks for specific words in the title of each post.
And if it finds that words, it replies to that particular post.
For example, we could write a book which looks for posts about Christmas, and if the bot finds that
the title contains the words Christmas, then the boat says, Merry Christmas.
So let's do that.
We first need to import the pro library and then creates a related instance, as I'm doing in here.
Then we said that we want to look through the posts of a subreddit, so we need to create a subreddit.
Let's say I'm working on the glassblowing subreddits, then we want to loop over four posts in sub Reddit.
That's new.
So this gives us this page.
So Reddit dot com slash or slash glassblowing slash new, which you get when you press that new bots
are there to sort posts by new.
Although this doesn't matter much because we will filter these by the last 48 hours anyway.
So the codes goes mostly like in the previous video.
We create the current time with dates time from date, time, import date time.
We also get the first time, so I explain this in the previous video, so you should watch that video
if you didn't dance so already.
Then we calculated the death toll.
And then we had a conditional which check if there is less or equal to 24 hours.
This time we were working on 48 hours, so two days.
And then what we do is we have a lease where we append these posts.
This time we don't want to append anything in the lease.
We don't want to write anything in a file.
So we remove that.
What we want to do is if we want to check if the word Christmas.
It's in force, though, it's the title.
But be careful because you should be lowering that title.
So the title could be, for example, as you see, this is Christmas with a Capital C, so you want
to make the entire title lowercase and then you can check for lowercase Christmas in the lowercase title.
So if Christmas in both the sides of the lower, then we see post dot replying, Hey, Christmas is
coming.
No, I'll koman this out.
Before I do that, I first check if.
I got the actual post title correctly, so let me run this, I also forgot to import Chinese.
So import events run again.
Yes, so we gave the correct post, as we see in the title.
Now let's try to add a reply to that post.
So run, and let's check now this post.
Yeah.
Hate Christmas is coming, so my comment is here.
It was added just now.
And that is how you add comments to a post on Reddit if you want to add comments to existing comments.
Then what you need to do is instead of that, you want to iterate for comments, then post those comments.
And if, let's say the word is coming in comments, that's body so common that it gives you the actual
taste of the comment.
If that's words, is in the comments.
So for example, in these comments that we just added lowercase, so let's just lower the case or the
comments than we do.
Comments that reply?
Yeah, it's coming.
Run that.
And of course, we do have this limitation of credits that we have to wait now seven minutes.
So I'll try after seven minutes.
Yes, or seven minutes have passed, so let's try this again.
It seems to be working, let's check.
Yes, so this is my comment, added, add this to an existing comment in a post in a subreddit.
So that is a complete code on how to reply to a post and how to reply to a comment in a post on Reddit.
Thank you.
I'll see you later.