1
00:00:00,990 --> 00:00:06,960
Will come back in this lecture and show you how to use your hospitality with Michael Python to send

2
00:00:06,960 --> 00:00:12,810
a post request to if this and that which will generate an email notification.

3
00:00:13,350 --> 00:00:19,290
And by the end of this, this email notification is going to look something like this in this example.

4
00:00:19,290 --> 00:00:27,000
And this notification email is just simply consisting of text and of code in here, three values that

5
00:00:27,000 --> 00:00:29,600
come from a sensor.

6
00:00:29,610 --> 00:00:36,060
In this case, I'm noticing a real sensor, but just dummy data from a random function on my hospital

7
00:00:36,060 --> 00:00:37,470
to make a Python script.

8
00:00:37,920 --> 00:00:43,690
I'm not using any hardware at all for these examples other than the specific to itself.

9
00:00:44,250 --> 00:00:50,370
So let's have a look at how you can go about implementing a function like this.

10
00:00:53,710 --> 00:00:59,710
Here, I've got my if this and that account I've already looked in, he can get a free account if he

11
00:00:59,710 --> 00:01:00,870
don't have one already.

12
00:01:01,120 --> 00:01:10,150
And this is my email applet that I'm targeting through my post history request on my micro python script.

13
00:01:10,710 --> 00:01:13,540
So I'll look inside first to see what that looks like.

14
00:01:14,440 --> 00:01:16,420
And I'm going to.

15
00:01:18,470 --> 00:01:20,030
Click on this part here to edit.

16
00:01:21,780 --> 00:01:29,670
The appellate and have a little sorry, so the appellate judge consisting of a subject which can contain

17
00:01:29,670 --> 00:01:33,720
ingredients in this case, the only including the record is the event name.

18
00:01:34,320 --> 00:01:42,960
And then they've got the body right here, which can contain some simple Timal, mostly text and of

19
00:01:42,960 --> 00:01:44,160
course, the ingredients.

20
00:01:44,400 --> 00:01:47,700
You can add ingredients from this list right here.

21
00:01:47,700 --> 00:01:49,610
So you can see it's not terribly rich.

22
00:01:49,620 --> 00:01:55,950
It's only got an event name, a time of occurrence and then three values that you can include in here.

23
00:01:56,220 --> 00:02:04,800
And that's why I have gone for three Dommy since Durov values and you can see right there and that's

24
00:02:04,800 --> 00:02:09,030
about it when I made it at a couple of breakpoints here.

25
00:02:10,860 --> 00:02:12,230
And then save.

26
00:02:15,630 --> 00:02:21,870
All right, so let's get back to normal now, considered connected and is waiting for a post request

27
00:02:21,870 --> 00:02:25,090
from my script on the other side.

28
00:02:25,110 --> 00:02:32,110
Now, on the macro Python side, I've got the sample script right here in the credentials file.

29
00:02:32,430 --> 00:02:37,030
Again, the credentials file is similar to what you have seen in the previous lectures.

30
00:02:37,050 --> 00:02:39,590
It's got my wi fi network credentials.

31
00:02:39,900 --> 00:02:47,430
But in this case, I also need the if this thing that key the key is what allows me to post to if this

32
00:02:47,430 --> 00:02:51,850
and that without my post being rejected by if this is that.

33
00:02:52,290 --> 00:03:01,380
So this is an important string that you need to get and to get that after you logged into your if the

34
00:03:01,380 --> 00:03:06,510
Senate account, go to your profile, you click on my services.

35
00:03:08,410 --> 00:03:10,570
Look for the Web service.

36
00:03:13,700 --> 00:03:21,790
And then click on the Coquille button and you'll see your efforts on that key right there.

37
00:03:22,550 --> 00:03:28,010
And so just copy that and put that into your Jason credentials file.

38
00:03:28,970 --> 00:03:31,540
So let's go back and I'm going to go.

39
00:03:32,570 --> 00:03:44,660
Into my micro python event, back into this, I'm just going to wait for activities, for activity records,

40
00:03:44,880 --> 00:03:50,330
so I'm just going to leave this page open and see any new activity coming through.

41
00:03:50,930 --> 00:03:52,790
So back to the script now.

42
00:03:53,360 --> 00:04:00,080
I've got information about all the various resources that will be using here, including if this and

43
00:04:00,080 --> 00:04:00,500
that.

44
00:04:01,070 --> 00:04:06,620
This is how you can create an account and learn more about the web hooks that will be using done in

45
00:04:06,620 --> 00:04:07,790
the script itself.

46
00:04:08,330 --> 00:04:14,270
You'll see that most of it now is familiar with scripts that you've seen, the previous few lectures

47
00:04:14,690 --> 00:04:23,090
and opening up the credentials file using the usual open construct, cutting the same header inserted

48
00:04:23,180 --> 00:04:28,970
earlier in the previous lecture, because I'll be sending a JSON payload to if this and that.

49
00:04:29,090 --> 00:04:36,040
That's a content type and this is the you are real for the post request.

50
00:04:36,470 --> 00:04:41,520
So the trigger has a name, which is you Python.

51
00:04:41,540 --> 00:04:46,010
This is the name of the event that I have created on if this and that.

52
00:04:46,890 --> 00:04:48,530
I send you to add that in here.

53
00:04:48,530 --> 00:04:56,210
And then after the with a key component of the euro, I pass the efficient that key for my account.

54
00:04:56,210 --> 00:04:59,660
Remember, this is private is going to be different for you than what it is for me.

55
00:04:59,690 --> 00:05:07,490
So you need to get your if this and that key and paste it in here in the credentials file and that makes

56
00:05:07,490 --> 00:05:08,870
up the post.

57
00:05:08,870 --> 00:05:09,550
You are real.

58
00:05:10,340 --> 00:05:15,540
There's no change to the do connect method and lines.

59
00:05:15,800 --> 00:05:23,930
Sixty three, sixty five are identical then I'm not repeating this operation more than one.

60
00:05:23,960 --> 00:05:30,830
So I'm only doing a single post request to the official that every time that I click on the play button,

61
00:05:31,250 --> 00:05:35,810
I don't have a timer to trigger these emails again.

62
00:05:36,050 --> 00:05:38,960
And I'm not using an infinite loop because there's something I want to do.

63
00:05:38,960 --> 00:05:44,830
Only occasionally I'm just going to do it when I actually click on the play button.

64
00:05:46,070 --> 00:05:53,660
So when I click on the play button, the script is going to create those three random dummy sensor values

65
00:05:53,660 --> 00:05:55,370
for temperature, humidity and pressure.

66
00:05:55,760 --> 00:06:02,930
I'll create the Jason document like this by passing those random values across knowledge that have got

67
00:06:02,930 --> 00:06:09,910
value one, value two and value three four the names of these key value pairs.

68
00:06:09,910 --> 00:06:12,710
So these are keys for those values.

69
00:06:13,040 --> 00:06:21,560
So I'm using the same names as the names for the ingredients in the efficient that app.

70
00:06:23,250 --> 00:06:31,860
Or applet, and then in line 80, I'm doing the post request, those requests to post.

71
00:06:32,920 --> 00:06:42,280
And putting the euro ahead, US and the chase and data file waiting for the response to come back and

72
00:06:42,280 --> 00:06:46,990
his response content stored inside the efficient debt, and it's called back variable.

73
00:06:47,290 --> 00:06:53,980
And then I'm simply printing that response to the schill while I wait for that email to arrive in my

74
00:06:54,010 --> 00:06:54,760
email account.

75
00:06:55,270 --> 00:06:57,960
OK, so let's go ahead and try this in practice.

76
00:06:57,970 --> 00:07:06,130
I have already uploaded the efficient credentials file to the tune and I'm going to click on the play

77
00:07:06,130 --> 00:07:08,440
button to execute the script.

78
00:07:09,370 --> 00:07:10,550
OK, try again.

79
00:07:11,320 --> 00:07:16,660
Yeah, does take a couple of times to do this, maybe the security is running something in the background

80
00:07:17,410 --> 00:07:20,210
anyway, so got successful response.

81
00:07:20,220 --> 00:07:31,360
So they try to send through this Jason payload and we got congratulations from if this is that if I

82
00:07:31,360 --> 00:07:36,100
refresh this page, I should see.

83
00:07:37,770 --> 00:07:41,940
Information that my Web hook was successfully.

84
00:07:43,710 --> 00:07:51,570
Received, so there is value one, two and three, so this that these values match with the values that

85
00:07:51,570 --> 00:07:53,400
the authorities did send.

86
00:07:54,270 --> 00:07:56,650
And then have a look at my.

87
00:07:58,720 --> 00:08:00,910
An email.

88
00:08:02,870 --> 00:08:09,030
And she received an email bagenal with this payload as well.

89
00:08:09,050 --> 00:08:14,780
So it was moved things aside, to be able to compare the virus.

90
00:08:15,200 --> 00:08:21,200
So there's temperature 47 degrees, humidity 48.

91
00:08:22,120 --> 00:08:23,920
And Patricia.

92
00:08:25,110 --> 00:08:25,890
64.

93
00:08:29,730 --> 00:08:35,260
I say, OK, so she can see this works quite well.

94
00:08:35,890 --> 00:08:39,840
It is relatively fast as well.

95
00:08:39,880 --> 00:08:43,570
I just did it one more time and.

96
00:08:45,510 --> 00:08:46,440
It's refresh.

97
00:08:48,580 --> 00:08:50,680
The activity page and.

98
00:08:52,620 --> 00:08:58,870
There's a new values, seventy seven for value, three, twenty nine for value, one, forty four for

99
00:08:58,880 --> 00:09:03,690
value two and a copy of the email that was sent out.

100
00:09:06,670 --> 00:09:07,680
See if it's arrived.

101
00:09:13,740 --> 00:09:14,790
And there's an email.

102
00:09:17,150 --> 00:09:24,230
All right, that works, so that's how you can use your especially two with micro python to send out

103
00:09:24,230 --> 00:09:27,440
a notification email via if this.

104
00:09:27,480 --> 00:09:31,860
And then, of course, now that you know how to do that, you'll be able to do many more things in the

105
00:09:31,900 --> 00:09:33,450
efficient that network.

106
00:09:34,190 --> 00:09:40,670
There is one more example in this section that I want to show you, and that is how to get current weather

107
00:09:40,670 --> 00:09:48,110
information for your location or any other location on the planet using the open weather map service.
