WEBVTT

00:06.260 --> 00:07.620
Everyone wrote them back.

00:07.860 --> 00:14.940
So in the previous video we saw that we finished the classification and the registration of the API.

00:15.030 --> 00:20.430
So the final thing that we need to do is to do the refill of the API.

00:20.430 --> 00:21.080
OK.

00:21.210 --> 00:23.360
So we're going to go go back here.

00:23.370 --> 00:29.190
So we're going to come back here and then we're going to finally write the Rayfield class which we did

00:29.190 --> 00:32.770
it in a similar video before so it shouldn't be something new.

00:32.770 --> 00:33.040
Right.

00:33.040 --> 00:35.860
So we're going to go through it fairly quickly OK.

00:36.060 --> 00:37.550
So that's a good start.

00:37.680 --> 00:40.970
So the first thing is we need to write a class which is called refill.

00:40.980 --> 00:41.820
Right.

00:41.940 --> 00:49.890
As the resource and we inherit from the resource class and then we said we discussed that it's going

00:49.890 --> 00:51.350
to be a post right.

00:51.390 --> 00:54.460
So we're going to see a post of self.

00:55.260 --> 00:59.750
And then first of all the first step in post is usually to get the post to do us or we're going to say

00:59.750 --> 01:05.030
a posted up equal to a request not get Jaisalmer.

01:06.390 --> 01:13.080
Once we have the posted data then we need to get the username password and the amount that is to be

01:13.080 --> 01:21.660
added right and be careful that the password here is not the user's password but rather the administrators

01:21.690 --> 01:22.700
password right.

01:22.800 --> 01:33.150
So we're going to say a user name username is equal to the posted data and then username password is

01:33.150 --> 01:35.540
equal to posted data.

01:35.820 --> 01:40.860
And then inside of it we're going to call it admin underscore P.W. and password.

01:41.160 --> 01:45.790
And then finally the amount is equal to the posted data.

01:46.560 --> 01:49.190
At the same amount.

01:49.260 --> 01:52.150
OK so it's going to send it in the field amount.

01:52.590 --> 01:57.240
OK so we have the username password and amount so the first thing is we need to check that this user

01:57.240 --> 01:58.030
exists.

01:58.200 --> 02:01.690
So I'm going to say if not user exists.

02:01.890 --> 02:06.640
Ok so if this username doesn't exist then what do I do.

02:06.960 --> 02:11.090
Well I return an error as I say return.

02:11.160 --> 02:16.500
Jason if I and then we're going to use the function that we wrote generate return dictionaries and when

02:16.490 --> 02:18.260
I say return.

02:18.720 --> 02:25.050
So here generate return Dictionnaire gate and then the error code is going to be 301 because there is

02:25.050 --> 02:29.000
an invalid username and for the message it might tell the user.

02:29.010 --> 02:34.070
Well you know what invalid you don't want to see invalid username username.

02:34.170 --> 02:35.050
OK.

02:35.400 --> 02:36.110
And that's it.

02:36.120 --> 02:38.970
So that's for the existence of the user.

02:38.970 --> 02:42.510
We also said that the administrator password might be incorrect.

02:42.580 --> 02:48.470
I'm going to say the correct administrative password should be no ABC 1 2 3.

02:48.480 --> 02:52.560
Ok so maybe that's the administrative password that we choose.

02:52.560 --> 03:01.200
So I'm going to say if not password is equal to correct password then in that case I'm going to return

03:02.610 --> 03:04.770
3 0 2 which is an incorrect password.

03:04.770 --> 03:11.740
So I'm going to say return Jason if I generate or actually it should be I think three or four.

03:11.940 --> 03:12.230
Right.

03:12.240 --> 03:20.420
Because it's it's the invalid administrator password so it's invalid.

03:20.670 --> 03:26.200
Adman's traitor password might have misspelled it it's fine.

03:26.710 --> 03:27.360
OK.

03:27.480 --> 03:37.170
So once we have that then the next step is to update our users or our users database so that he has

03:37.170 --> 03:38.360
the new amount right.

03:38.400 --> 03:39.800
So how am I going to do that.

03:39.930 --> 03:43.330
Well I'm going to do users that update.

03:43.560 --> 03:44.330
OK.

03:44.700 --> 03:49.570
And then in here choose the user which has the corresponding user name.

03:50.340 --> 03:56.280
And what I'm going to update them is I'm going to set his number off tokens so I'm going to do a dollar

03:56.280 --> 04:02.710
set and then I'm going to have changed the number of tokens he has to the amount.

04:02.730 --> 04:03.310
OK.

04:03.360 --> 04:06.350
So the amount here is whatever I sent.

04:07.350 --> 04:08.400
And that's should be.

04:08.410 --> 04:11.550
So the final thing is to return a success to the user.

04:11.570 --> 04:18.690
So I don't say congratulations you have your AP You know you've added refilled the correct amount of

04:19.500 --> 04:19.940
stuff.

04:19.950 --> 04:27.680
So I'm going to see a return on I and then generate return dictionary inside of it.

04:27.690 --> 04:28.830
I'm gonna give 200.

04:28.830 --> 04:31.620
So it's a success and I'm going to give them a message.

04:31.630 --> 04:33.460
I want to refill.

04:33.660 --> 04:36.620
So refill maybe successfully.

04:37.100 --> 04:38.280
OK.

04:38.460 --> 04:39.440
All right.

04:39.480 --> 04:40.770
So now that should be it.

04:40.770 --> 04:43.280
So we're done with the refill.

04:43.290 --> 04:49.020
We're done with the classify glass and we're done with the registration.

04:49.100 --> 04:49.560
OK.

04:49.620 --> 04:51.800
So we're done with all of the resources.

04:51.810 --> 04:53.940
Now we need to add them to the API.

04:54.090 --> 04:54.510
So I do.

04:54.540 --> 04:59.080
AP I got to add resource and resource.

04:59.250 --> 05:00.250
And then I'm going to add.

05:00.270 --> 05:01.880
First of all register.

05:02.620 --> 05:09.180
And if you remember from the image we said or from the chart we said we're going to do it at slash register.

05:09.240 --> 05:10.140
Okay.

05:10.560 --> 05:20.020
And then we're going to do API to add resource Rumana at the classify glass and we're going to put it

05:20.050 --> 05:31.500
at slash classified slash classify finally resigned you add the last resource which is the real.

05:32.130 --> 05:34.070
And we're going to add it as Slash free.

05:34.110 --> 05:36.570
Great.

05:37.330 --> 05:44.390
Finally the last step is as usual if name is equal to main.

05:44.450 --> 05:52.040
So if it's main then we do at Dharan and then host is equal to and this is the most important piece

05:52.040 --> 05:52.970
of the code.

05:53.030 --> 05:55.290
Zero point zero point zero point zero.

05:55.320 --> 05:55.920
OK.

05:56.030 --> 05:59.770
So this is the host and readouts are done with the API.

05:59.780 --> 06:02.820
Just almost 150 lines of code.

06:03.010 --> 06:03.770
Not too big.

06:03.800 --> 06:04.370
OK.

06:05.860 --> 06:07.260
That can make it smaller.

06:07.260 --> 06:13.390
Probably you know for example these things like updates we can write a function that up these things

06:13.420 --> 06:17.340
automatically so it can take this just in one line of code.

06:17.650 --> 06:23.720
For example this update to you can change it in one line of code so you can do a lot of stuff here.

06:23.780 --> 06:29.190
Let's let us remove these two Tutu's because we're done with them to do it right.

06:29.230 --> 06:31.860
So yeah hopefully this wasn't too hard.

06:32.320 --> 06:40.390
It's just the main idea here is the classifying class and actually everything beyond this area here

06:40.510 --> 06:42.250
is actually pretty old.

06:42.280 --> 06:43.920
So we've discussed it before.

06:43.960 --> 06:49.870
So the only new area here I would say is the request get your elso we got that you are well from the

06:49.940 --> 06:55.170
requests we generated the result Jason or dictionary.

06:55.240 --> 07:02.710
And then we opened the image store that so we store the the image from their request that we got from

07:02.710 --> 07:07.590
their request and then we opened a new process and we ran in it.

07:07.600 --> 07:12.480
Lifeson classified image model directory in my file.

07:12.490 --> 07:17.910
Then I communicated with the process and I waited until the process subprocesses done.

07:18.010 --> 07:27.290
And finally this process year we changed it so that it writes text that DST file and that and it stores

07:27.310 --> 07:28.430
and dumps in it.

07:28.740 --> 07:30.890
The risk very turned up.

07:31.120 --> 07:38.930
So what I do here is to open it and retrieve the dictionary once I have that then I'm willing to return.

07:39.140 --> 07:41.360
Richard Jewson and that's about it.

07:41.360 --> 07:46.840
So we're going to stop here and the next video we're going to be testing the API just see how it works

07:47.110 --> 07:49.020
how we can interact with it.

07:49.150 --> 07:54.610
And you know see if it can work correctly classify a couple of images so let's give it a image of a

07:54.610 --> 07:58.520
zebra or a panda and see if it works or not.

07:58.570 --> 08:02.670
They're just up here and will pick up in the next minute or so until the next minute.

08:02.740 --> 08:03.490
Happy Cody.
