1
00:00:01,600 --> 00:00:08,560
Hi, there in this video, I'll show you how to create a program which sends an SMS to you to your phone

2
00:00:08,560 --> 00:00:15,550
number whenever the price of a particular Amazon product changes.

3
00:00:17,050 --> 00:00:20,650
So you select a product on Amazon, for example.

4
00:00:23,960 --> 00:00:28,670
I will use these pipes for this project.

5
00:00:29,060 --> 00:00:31,880
So who doesn't want to buy pipes?

6
00:00:32,270 --> 00:00:33,380
So that's a good example.

7
00:00:33,650 --> 00:00:41,360
And whenever the price of this product changes, you will receive an estimates in a phone number that

8
00:00:41,360 --> 00:00:41,930
you choose.

9
00:00:43,340 --> 00:00:49,520
And of course, you can either choose to get an estimate when the price drops or when it increases.

10
00:00:49,880 --> 00:00:54,290
So that's something that you can easily adjust in the program.

11
00:00:54,920 --> 00:01:03,610
And so the program will run all the time and it will automatically detect the change and send you the

12
00:01:03,740 --> 00:01:04,940
SMS automatically.

13
00:01:05,600 --> 00:01:11,360
So let's go to our python environment and imposed the necessary libraries.

14
00:01:14,340 --> 00:01:18,840
So we will use selenium to scrape the price of a product.

15
00:01:20,230 --> 00:01:22,560
So that's the value we want to scrape.

16
00:01:25,120 --> 00:01:29,770
Specifically, we need the whip driver function.

17
00:01:32,110 --> 00:01:41,290
So that's a library that is needed to scrape the value and then the library that you need to send the

18
00:01:41,290 --> 00:01:45,130
new price to the user by SMS is Twilio.

19
00:01:45,580 --> 00:01:52,840
So from three new dot tourists, we need to import client like that.

20
00:01:53,170 --> 00:01:53,620
That's it.

21
00:01:53,800 --> 00:01:58,720
Now I did cover both Selenium and Twilio in the previous videos.

22
00:01:59,080 --> 00:02:06,250
So in order to understand to better understand this video, you should have taken those videos first.

23
00:02:06,550 --> 00:02:17,230
So the web scraping part with selenium and the eSIMs sending functionality with Twilio since I did explain

24
00:02:17,230 --> 00:02:18,670
how to do this things.

25
00:02:18,970 --> 00:02:24,880
So same thing is Amazon scraping, then I'm not going to type in all the code, but I'm going to just

26
00:02:25,390 --> 00:02:30,760
use the code that I already have written in those videos.

27
00:02:31,150 --> 00:02:35,050
So one of those pieces of code is this function.

28
00:02:35,710 --> 00:02:40,150
Get driver or let me fix a typo here.

29
00:02:40,480 --> 00:02:42,220
Try for.

30
00:02:44,250 --> 00:02:52,590
So this function is responsible only for one thing, it is responsible to establish a whip driver,

31
00:02:52,890 --> 00:02:59,850
which is some type of object that establishes a connection with the web page.

32
00:03:00,030 --> 00:03:02,760
So that's a web page that we will scrape.

33
00:03:03,610 --> 00:03:03,820
Hmm.

34
00:03:04,080 --> 00:03:04,890
So that's a link.

35
00:03:04,890 --> 00:03:07,380
You can find this in the resources as well.

36
00:03:07,710 --> 00:03:10,380
So that's a link that points to this particular page.

37
00:03:10,740 --> 00:03:12,420
That's one in there in the browser.

38
00:03:14,770 --> 00:03:20,290
So that is to create the driver object that points to that Web page.

39
00:03:20,510 --> 00:03:26,920
Now next is to extract the actual value out of this page.

40
00:03:27,310 --> 00:03:34,210
To do that, we need to use another function which is responsible for scraping that value.

41
00:03:35,140 --> 00:03:36,730
So let's say this one.

42
00:03:37,550 --> 00:03:37,900
Let me.

43
00:03:41,090 --> 00:03:51,060
So the main driver, we get the driver of dysfunction here, so that is gets the driver get gets driver.

44
00:03:51,100 --> 00:03:51,380
Yes.

45
00:03:51,890 --> 00:03:59,300
And then we find the element by experts to do this.

46
00:03:59,360 --> 00:04:01,640
And I would suggest to use Google Chrome.

47
00:04:01,940 --> 00:04:09,170
So you open up Google Chrome and then you right click in here, go to inspect elements.

48
00:04:09,350 --> 00:04:12,380
So inspect and that would point to to this.

49
00:04:12,980 --> 00:04:16,910
Then you right click here, go to copy and go to experts.

50
00:04:19,060 --> 00:04:30,030
Go back to the code and you should paste that to the value so they're inside quotes the ghost that SPF.

51
00:04:30,700 --> 00:04:33,670
So with that, I can just print mean.

52
00:04:34,560 --> 00:04:39,730
Uh, so the call of that function and see if we got the value correctly.

53
00:04:50,640 --> 00:04:52,080
Yeah, so it seems to be working.

54
00:04:52,380 --> 00:04:55,350
However, we need to clean this string.

55
00:04:55,590 --> 00:05:04,680
We need to remove that dollar sign and convert it into a float because this is just a string object

56
00:05:04,680 --> 00:05:05,100
type.

57
00:05:05,640 --> 00:05:08,580
We need to use the no version of that.

58
00:05:10,300 --> 00:05:11,860
For that, I have another function.

59
00:05:14,980 --> 00:05:24,340
With a place in here, clean prize, so clean prize gets the string, the raw string, which is this

60
00:05:25,330 --> 00:05:26,260
as inputs.

61
00:05:26,680 --> 00:05:30,040
And it replaces the dollar sign with an empty shrink.

62
00:05:31,320 --> 00:05:33,930
And it's converts that into a float.

63
00:05:34,200 --> 00:05:36,360
So let's see what the output of this is.

64
00:05:36,990 --> 00:05:46,710
Clean prose This expects this row argument, which is so let's say raw prices are variable that is equal

65
00:05:46,710 --> 00:05:47,300
to Maine.

66
00:05:47,310 --> 00:05:55,320
So Maine gives us this roe string and then we pass the rural price in there and run.

67
00:06:01,050 --> 00:06:05,520
And now we get a clean no, which is a float.

68
00:06:06,270 --> 00:06:08,730
So let's carry on, we have the value now.

69
00:06:08,880 --> 00:06:12,320
We are ready to send out the estimates for that.

70
00:06:12,330 --> 00:06:19,500
You need to go to trial you and I show you all to to create a Twilley account in the previous videos.

71
00:06:19,830 --> 00:06:23,730
Again, in the section about sending SMS.

72
00:06:24,060 --> 00:06:31,620
So you should go to trial you and then you get an account as I.D. and an authentication token as well,

73
00:06:31,920 --> 00:06:34,110
and you will also get a phone number.

74
00:06:34,650 --> 00:06:42,840
So that is the phone number or the sender, because the SMS will be sent from one number, which is

75
00:06:42,840 --> 00:06:48,090
given by Twilio to you to another number, which is probably your phone.

76
00:06:48,090 --> 00:06:49,440
Your personal phone number.

77
00:06:50,700 --> 00:06:53,390
So that's sensor, no, no.

78
00:06:54,690 --> 00:07:02,430
And those accounts aside and offer execution tokens should go in some variables like that.

79
00:07:03,390 --> 00:07:09,660
So you should use your own account as I.D. and authentication token for this to work this to will not

80
00:07:09,660 --> 00:07:14,540
work in your case and then you create a client instance.

81
00:07:14,580 --> 00:07:18,240
So the client is a class that we import imported here on top.

82
00:07:19,020 --> 00:07:27,720
And then what do we want to do is we want to send an eSIM is only when the price changes.

83
00:07:28,110 --> 00:07:30,570
So let's see how we can do that.

84
00:07:32,790 --> 00:07:43,950
First of all, we get the initial price right, we get the real price and we convert its year into price.

85
00:07:45,570 --> 00:07:47,800
So that's a Colin price.

86
00:07:47,860 --> 00:07:48,210
Right.

87
00:07:48,210 --> 00:07:55,110
So we get the price once and then we check with a while loop one through.

88
00:07:55,290 --> 00:07:59,430
We check if this initial price will change with time.

89
00:07:59,820 --> 00:08:03,000
So with time, we set time.

90
00:08:03,000 --> 00:08:04,260
So that's important time.

91
00:08:05,430 --> 00:08:07,140
And say what?

92
00:08:07,140 --> 00:08:09,510
Through time that sleep.

93
00:08:11,130 --> 00:08:19,830
So the script runs, it gets the price immediately and then it waits for No, that is off to you, right?

94
00:08:20,490 --> 00:08:22,350
How long you will wait?

95
00:08:22,650 --> 00:08:24,760
How often do you want to check the price?

96
00:08:24,800 --> 00:08:32,700
You want to check it for every one hour, every 24 hours, maybe one hour, it'd be a meaningful value.

97
00:08:33,090 --> 00:08:37,679
So for one hour, you'd have to enter three thousand six hundred.

98
00:08:38,159 --> 00:08:39,750
So that is seconds.

99
00:08:39,780 --> 00:08:43,049
One hour is equal to three thousand six hundred seconds.

100
00:08:43,710 --> 00:08:46,320
And the sleep method too works in seconds.

101
00:08:46,320 --> 00:08:47,790
So that's why you have to define that.

102
00:08:48,210 --> 00:08:54,360
But just for testing this now, I'll use just five to save the loopy surrounding or not.

103
00:08:55,110 --> 00:09:03,060
And then once we wait for that interval, then it makes sense to get the price again.

104
00:09:03,390 --> 00:09:11,400
So I'm going to copy those and pay them here together or price convert converted into a clean float

105
00:09:11,730 --> 00:09:12,450
again.

106
00:09:12,480 --> 00:09:15,930
And then we want to compare the two.

107
00:09:15,930 --> 00:09:17,730
But this is a bit tricky now.

108
00:09:18,120 --> 00:09:23,730
So what do we compare if price is smaller than price?

109
00:09:25,170 --> 00:09:26,760
This doesn't make much sense.

110
00:09:28,530 --> 00:09:39,690
So what we use in these cases, when you want to compare the last two values, then it's good to use.

111
00:09:40,110 --> 00:09:43,530
At least what I mean by that is.

112
00:09:45,470 --> 00:09:49,550
When you give the price, initially you see prices, let's say this is a list.

113
00:09:50,330 --> 00:09:56,180
And that list will first have this price, right?

114
00:09:56,600 --> 00:10:05,600
Then we say, well, through time that sleep, we get the price again and then we append.

115
00:10:09,470 --> 00:10:12,560
That's price to the list at this point.

116
00:10:12,590 --> 00:10:18,530
If I print out the list prices, you should see a list with two prices.

117
00:10:25,180 --> 00:10:25,420
Yeah.

118
00:10:25,570 --> 00:10:29,980
So sixteen point thirty three, sixteen point thirty three.

119
00:10:30,760 --> 00:10:40,000
Again, another price is added to the list every five seconds, a new price will be added to the list.

120
00:10:40,540 --> 00:10:45,970
In this case, of course, is the same price because the price is not changing every five seconds.

121
00:10:47,020 --> 00:10:49,300
And so one and so forth.

122
00:10:49,510 --> 00:10:51,550
So let me stop that now.

123
00:10:52,720 --> 00:10:57,010
OK, so we got the price into a list now we can compare.

124
00:10:57,490 --> 00:11:08,140
What we want to compare, of course, is if prices minus one is less than prices.

125
00:11:09,680 --> 00:11:19,610
Minus two, so what I'm doing here is I'm comparing the last item of the lease with an item before the

126
00:11:19,610 --> 00:11:20,840
last item.

127
00:11:21,200 --> 00:11:28,840
So this is this that is that now.

128
00:11:29,240 --> 00:11:31,490
More specifically, it would be.

129
00:11:32,360 --> 00:11:44,120
Actually, this is that and that is that because we don't want to append numbers endlessly to this list,

130
00:11:44,330 --> 00:11:49,490
we want to remove the oldest prices from there.

131
00:11:49,820 --> 00:11:52,370
So here we Cynthia Smith.

132
00:11:52,700 --> 00:11:55,070
Let's say the code will be here for sending the estimates.

133
00:11:55,070 --> 00:11:56,990
We will implement that in just a bit.

134
00:11:57,440 --> 00:11:59,600
But then afterwards, we want to say deal.

135
00:11:59,930 --> 00:12:03,140
So delete prices minus two.

136
00:12:04,100 --> 00:12:11,270
So let's say pass for now for this and let me print out the list again prices.

137
00:12:11,810 --> 00:12:21,230
So in this case, we will drop the oldest prices from the list, the oldest items on the list and keep

138
00:12:21,230 --> 00:12:23,030
only the loss through prices.

139
00:12:23,270 --> 00:12:29,900
So that allows us to compare the last the current price with a lowest price.

140
00:12:31,580 --> 00:12:33,740
Let's see what we get in the second loop.

141
00:12:35,880 --> 00:12:45,960
Yeah, so it's always the lowest price in the least, so at this point when we print this out, we don't

142
00:12:45,960 --> 00:12:50,100
have that price, that item.

143
00:12:50,460 --> 00:12:57,720
If you replace this and place it in here, you should see two prices.

144
00:12:58,680 --> 00:13:07,050
So before we print out the list, before we delete that other price, yes or no, we have to price and

145
00:13:07,050 --> 00:13:11,580
these are always the last two prices.

146
00:13:12,830 --> 00:13:14,720
As you can see and so on and so forth.

147
00:13:15,710 --> 00:13:17,720
So if price minus one.

148
00:13:19,560 --> 00:13:22,560
Got less than the last price.

149
00:13:22,890 --> 00:13:30,600
Then we send our SMS, the codes for that is the code that I showed you in the Smith's sending section

150
00:13:30,600 --> 00:13:33,580
of the course, and it looks like this.

151
00:13:33,580 --> 00:13:35,250
So you create a message.

152
00:13:36,030 --> 00:13:38,250
It points to the client variable.

153
00:13:38,460 --> 00:13:46,740
So this instance and it points to messages that creates this is the body of the message here you right?

154
00:13:47,190 --> 00:13:49,050
The price has just dropped, too.

155
00:13:49,440 --> 00:13:51,330
Well, here goes.

156
00:13:51,390 --> 00:13:57,840
Price the variable that holds the price for the latest price.

157
00:13:58,680 --> 00:14:00,870
So that one in there the claim price.

158
00:14:03,140 --> 00:14:11,180
From this is the number you see in your three year page, so the center of this maybe is your personal

159
00:14:11,180 --> 00:14:11,600
number.

160
00:14:11,810 --> 00:14:13,520
Where do you want to receive the message?

161
00:14:14,870 --> 00:14:21,950
So this will be executed only when this item here is less than that.

162
00:14:22,850 --> 00:14:26,270
That is the only time when an SMS will be sent out.

163
00:14:27,920 --> 00:14:32,630
So that is what I wanted to show you how to implement this Xmas.

164
00:14:35,010 --> 00:14:37,260
Notification program.

165
00:14:38,860 --> 00:14:45,040
That detects changes in the prices, so it's maybe more simple than you thought.

166
00:14:46,480 --> 00:14:53,140
In the next video, I'll show you how to change this from eSIMs to email to so to send out an email

167
00:14:53,140 --> 00:14:53,920
instead of a service.

168
00:14:54,160 --> 00:14:54,700
See you there!

