1
00:00:00,090 --> 00:00:08,070
In this video, we will write a script which gets all the posts submitted by the user in the last 24

2
00:00:08,070 --> 00:00:12,700
hours in a particular subreddit in any subreddits, actually.

3
00:00:12,720 --> 00:00:16,830
But as an example, we will work on this subreddits.

4
00:00:17,310 --> 00:00:21,930
This subreddit is a boat blowing glass, so creating glass.

5
00:00:25,300 --> 00:00:27,130
Which looks like this more or less.

6
00:00:27,670 --> 00:00:36,880
And I chose this subreddit because this is a relatively low number of submissions per 24 hours, so

7
00:00:36,880 --> 00:00:43,090
it's not a very popular subreddit, which means it's a good subreddit to experiment with.

8
00:00:43,570 --> 00:00:51,190
For example, we see that in the last 24 hours, there are about four or five submissions by users.

9
00:00:51,700 --> 00:00:59,290
So we're going to check that if we also go to these four or five submissions in our Python codes.

10
00:01:00,280 --> 00:01:04,540
That way, we can evaluate the accuracy of our scripts.

11
00:01:05,140 --> 00:01:13,110
So to do this, you need to have a Reddit account and also creates an app in Reddit.

12
00:01:13,120 --> 00:01:17,920
I showed how to do that in the previous video, and also you need to create or edit instance.

13
00:01:18,880 --> 00:01:25,960
Using that glass and putting all your dots in here, I also showed this how to do in the previous video.

14
00:01:26,740 --> 00:01:38,440
So now what we need to do is this time we need to create a subreddit instance which comes from Reddit.

15
00:01:38,680 --> 00:01:40,410
So that's valuable.

16
00:01:41,450 --> 00:01:43,630
Come here, Dot Sub.

17
00:01:43,940 --> 00:01:44,870
Read it.

18
00:01:46,070 --> 00:01:49,430
So this now gets as string a subreddit.

19
00:01:50,030 --> 00:01:57,170
The subreddit is the name as a stream goes the title of a name of a subreddit.

20
00:01:57,500 --> 00:02:05,280
You can see it here glassblowing, and you can also seeds after the or slash glassblowing.

21
00:02:05,600 --> 00:02:07,600
So glassblowing goes here.

22
00:02:07,730 --> 00:02:09,710
Glass blowing.

23
00:02:11,050 --> 00:02:21,310
Then once we have a subreddit, we want to iterate for posts in subreddits, that's new.

24
00:02:21,310 --> 00:02:26,800
The new methods will give us the new posts in that subreddits.

25
00:02:27,100 --> 00:02:30,490
So that will give us a list of posts.

26
00:02:30,940 --> 00:02:40,300
Then we need to apply a condition, something like if a post is in the recent 24 hours, then we print

27
00:02:40,300 --> 00:02:40,690
it out.

28
00:02:41,590 --> 00:02:48,910
So before we apply that, we first need to get to the time, the current time and the time when a submission

29
00:02:48,910 --> 00:02:50,770
was created.

30
00:02:51,160 --> 00:03:00,830
So let's first give the current time current time a variable is equal to date time dot UTC.

31
00:03:00,850 --> 00:03:10,000
Now we also have the now methods, but be aware that this method gives you the local time off your computer

32
00:03:10,000 --> 00:03:18,550
or of the report server, but UTC will give you the UTC time in the UTC system.

33
00:03:18,760 --> 00:03:19,810
So this is good.

34
00:03:19,810 --> 00:03:27,430
So when you are doing comparisons between different times, as we are doing now, and of course, we

35
00:03:27,430 --> 00:03:29,230
need to import from dates.

36
00:03:31,910 --> 00:03:33,740
Time, imports date.

37
00:03:34,760 --> 00:03:37,700
Time, so that goes here.

38
00:03:38,300 --> 00:03:40,770
No, that's the current time.

39
00:03:40,790 --> 00:03:41,840
And what is the.

40
00:03:43,320 --> 00:03:51,570
Posts created time or post time that is post Dot.

41
00:03:53,450 --> 00:04:03,800
Created so the post is one of the posts in the subreddits, one of these submissions, that's one it

42
00:04:03,800 --> 00:04:08,780
will be this one also and also be aware that there are ads.

43
00:04:08,900 --> 00:04:11,660
So this is an ad you see promoted here.

44
00:04:11,730 --> 00:04:16,399
This will not be included in the list of submissions because it is not a submission.

45
00:04:16,399 --> 00:04:17,000
It is in that.

46
00:04:17,600 --> 00:04:27,440
So post time post creators, well, that's trying to print out current time and post time to see what

47
00:04:27,440 --> 00:04:28,340
we actually get.

48
00:04:29,150 --> 00:04:29,870
So around that?

49
00:04:31,400 --> 00:04:35,480
And this is the ultimate so current time, is this one you?

50
00:04:37,010 --> 00:04:39,020
And post time is this one.

51
00:04:39,260 --> 00:04:42,890
So they are in a very different formats, four from each other.

52
00:04:43,040 --> 00:04:51,710
So this is like a timestamp in seconds v seconds, ah, from 1st of January 1973.

53
00:04:51,980 --> 00:04:57,110
So it's still a timestamp, but it's in seconds and it starts from a particular point in time.

54
00:04:57,500 --> 00:05:03,590
We need to convert this to into a common format and then get the difference out of them.

55
00:05:04,010 --> 00:05:08,330
So I think it makes more sense to convert this into data time to do that.

56
00:05:09,440 --> 00:05:12,560
So that is the post time we get post creates.

57
00:05:12,560 --> 00:05:26,720
It's of when we put that post created as inputs of date time dot UTC from time to time.

58
00:05:27,260 --> 00:05:35,510
So that is a method of date time which gets seconds as inputs and in three turns this kind of formats.

59
00:05:35,630 --> 00:05:38,950
So now if we run this again, we should see the same format.

60
00:05:39,560 --> 00:05:44,390
So that is the current time, and that is the time when the post was created.

61
00:05:44,570 --> 00:05:48,320
So there are many posts in here for each pair.

62
00:05:48,320 --> 00:05:51,390
We need to calculate the Daily Star.

63
00:05:51,870 --> 00:05:59,390
So the difference between the time where the post was created and the current time so that we check

64
00:05:59,390 --> 00:06:02,330
if 24 hours have passed or not.

65
00:06:03,860 --> 00:06:11,900
So let's say delta time is equal to current time minus post time.

66
00:06:14,260 --> 00:06:15,340
And let's bring the notes.

67
00:06:22,110 --> 00:06:25,170
So this is what we get, yeah, I start from.

68
00:06:27,780 --> 00:06:37,110
Here, some of the most recent pause was made before four hours and 54 minutes, thirty four seconds,

69
00:06:37,470 --> 00:06:46,260
then another post was submitted before eight hours and 25 minutes ago, more or less 10 hours 12.

70
00:06:46,260 --> 00:06:48,390
And then we have one day and so one.

71
00:06:49,810 --> 00:07:00,010
So let's filter them out by getting only reports that are earlier than 24 hours for that we needs and

72
00:07:00,010 --> 00:07:11,650
if conditional, so if delta time is less or equal to 24 hours.

73
00:07:12,640 --> 00:07:15,940
But be careful, how do you represent 24 hours?

74
00:07:16,270 --> 00:07:18,940
You cannot just say 24 like that, right?

75
00:07:18,970 --> 00:07:24,970
Because you want to compare a delta time type with a delta time type.

76
00:07:25,120 --> 00:07:27,200
But this is not a delta time type.

77
00:07:27,220 --> 00:07:28,330
This is an integer.

78
00:07:28,870 --> 00:07:34,600
So what you want to do instead is you need the same type of object.

79
00:07:35,680 --> 00:07:42,880
So for that, we need to import from the time we need time, they'll tell us when we can create a time

80
00:07:42,880 --> 00:07:48,220
delta object, which has the same type as this object.

81
00:07:48,430 --> 00:07:56,950
So this object is created implicitly through the difference of two different time stamps, but still,

82
00:07:56,950 --> 00:07:59,380
you get the time delta from that difference.

83
00:07:59,620 --> 00:08:04,060
So now we can see how worse equals twenty.

84
00:08:05,260 --> 00:08:11,980
You see, this gets this whole worse argument, and it also has other arguments you can pass or if you

85
00:08:11,980 --> 00:08:12,190
want.

86
00:08:12,190 --> 00:08:17,730
It's a more accurate delta, such as 24 hours, one hour, two minutes and 30 seconds.

87
00:08:17,740 --> 00:08:23,110
You could do that by adding arguments here like, I mean, it's equal to that and so on.

88
00:08:23,260 --> 00:08:26,830
But for us, in this case, it's 24 hours.

89
00:08:27,220 --> 00:08:40,030
So if that is the case, then print paused but paused, as you know, simply gives you that idea of

90
00:08:40,030 --> 00:08:40,600
the post.

91
00:08:40,600 --> 00:08:49,870
So perhaps you won the title and then you want self text the body of the post the content.

92
00:08:50,470 --> 00:08:51,340
So we were on that.

93
00:08:52,090 --> 00:08:56,980
But first, maybe you want to uncommon that there and to run again.

94
00:09:00,740 --> 00:09:02,390
So this is what we get.

95
00:09:03,740 --> 00:09:07,760
So we have one force here to in here.

96
00:09:09,520 --> 00:09:12,650
Which corresponds with the.

97
00:09:12,910 --> 00:09:16,330
So another one is the title of this.

98
00:09:18,070 --> 00:09:19,870
And the title of that post.

99
00:09:20,380 --> 00:09:22,510
So another one this on.

100
00:09:24,360 --> 00:09:31,650
Now, if you want to save these into a list instead, you'd have to create an entire list before the

101
00:09:31,650 --> 00:09:32,160
loop.

102
00:09:32,280 --> 00:09:42,870
So like all outputs or just posts 24 posts like that, that is equal to an empty list of when instead

103
00:09:42,870 --> 00:09:49,170
of printing these titles and self-tests out, you want to refer to posts.

104
00:09:49,170 --> 00:10:00,570
24 hours does append and keep adding, perhaps pulse or post the title and post the self text.

105
00:10:01,470 --> 00:10:08,580
And of course, you can keep adding information that you want to be included, like posts created.

106
00:10:10,100 --> 00:10:19,760
And so on, and then you can print out the entire post 24 hours list and see what formats we get.

107
00:10:21,840 --> 00:10:22,650
So there we go.

108
00:10:24,330 --> 00:10:25,860
So the list starts here.

109
00:10:26,550 --> 00:10:31,300
You see the square parentheses and then we have the title.

110
00:10:31,320 --> 00:10:39,390
So the first table with the title of the first post, there's no content in that post, just a picture

111
00:10:39,570 --> 00:10:43,080
and then you have the timestamp in seconds.

112
00:10:43,560 --> 00:10:50,820
So if you want to convert that into a date time in human friendly date time, you want to apply again

113
00:10:50,820 --> 00:10:55,380
that method to post created or just say here.

114
00:10:55,960 --> 00:10:56,670
Post.

115
00:10:58,720 --> 00:11:00,220
Time and run again.

116
00:11:03,900 --> 00:11:05,520
So small tongue.

117
00:11:06,680 --> 00:11:08,390
Oh, that's the date time.

118
00:11:08,660 --> 00:11:17,270
And of course, you can also further convert it into a string using the SDR f time methods as a so won't

119
00:11:17,270 --> 00:11:21,080
you see that we got these posts in a list?

120
00:11:22,070 --> 00:11:26,750
And of course, you could go even further and store them in a text file?

121
00:11:26,990 --> 00:11:39,530
And so we can do that by opening a text file with open outputs, the T60 in rights mode as a file,

122
00:11:40,400 --> 00:11:45,500
and we indent all of this for a loop under the with context manager.

123
00:11:45,860 --> 00:11:57,620
So for posting subreddits, if they also time I saw less than 24 hours, then we'd say under the conditional

124
00:11:57,620 --> 00:12:02,270
here indented, we see file rights.

125
00:12:03,350 --> 00:12:14,480
And three rides, a knife string, perhaps so, which has posted the title, a brake line post dot self.

126
00:12:15,170 --> 00:12:17,690
Text, let me expand this.

127
00:12:18,290 --> 00:12:27,290
Perhaps a double brake line of a van will store the next title and post, so we don't need to putting

128
00:12:27,320 --> 00:12:29,330
that out this time we just run.

129
00:12:30,770 --> 00:12:32,300
This is odd for the taxi.

130
00:12:33,260 --> 00:12:34,700
And that's the results.

131
00:12:34,700 --> 00:12:35,690
NATO, X-File.

132
00:12:36,350 --> 00:12:39,530
So the title and it doesn't have any content.

133
00:12:41,460 --> 00:12:45,060
Then we have the title of the next post, its contents in here.

134
00:12:45,810 --> 00:12:48,180
The title of the other post and so on.

135
00:12:49,590 --> 00:12:53,070
So that's the complete code for this lecture.

136
00:12:53,430 --> 00:12:53,920
Thank you.

137
00:12:54,120 --> 00:12:55,200
And I'll talk to you later.

