Will come back in this lecture and show you how to use your hospitality with Michael Python to send
a post request to if this and that which will generate an email notification.
And by the end of this, this email notification is going to look something like this in this example.
And this notification email is just simply consisting of text and of code in here, three values that
come from a sensor.
In this case, I'm noticing a real sensor, but just dummy data from a random function on my hospital
to make a Python script.
I'm not using any hardware at all for these examples other than the specific to itself.
So let's have a look at how you can go about implementing a function like this.
Here, I've got my if this and that account I've already looked in, he can get a free account if he
don't have one already.
And this is my email applet that I'm targeting through my post history request on my micro python script.
So I'll look inside first to see what that looks like.
And I'm going to.
Click on this part here to edit.
The appellate and have a little sorry, so the appellate judge consisting of a subject which can contain
ingredients in this case, the only including the record is the event name.
And then they've got the body right here, which can contain some simple Timal, mostly text and of
course, the ingredients.
You can add ingredients from this list right here.
So you can see it's not terribly rich.
It's only got an event name, a time of occurrence and then three values that you can include in here.
And that's why I have gone for three Dommy since Durov values and you can see right there and that's
about it when I made it at a couple of breakpoints here.
And then save.
All right, so let's get back to normal now, considered connected and is waiting for a post request
from my script on the other side.
Now, on the macro Python side, I've got the sample script right here in the credentials file.
Again, the credentials file is similar to what you have seen in the previous lectures.
It's got my wi fi network credentials.
But in this case, I also need the if this thing that key the key is what allows me to post to if this
and that without my post being rejected by if this is that.
So this is an important string that you need to get and to get that after you logged into your if the
Senate account, go to your profile, you click on my services.
Look for the Web service.
And then click on the Coquille button and you'll see your efforts on that key right there.
And so just copy that and put that into your Jason credentials file.
So let's go back and I'm going to go.
Into my micro python event, back into this, I'm just going to wait for activities, for activity records,
so I'm just going to leave this page open and see any new activity coming through.
So back to the script now.
I've got information about all the various resources that will be using here, including if this and
that.
This is how you can create an account and learn more about the web hooks that will be using done in
the script itself.
You'll see that most of it now is familiar with scripts that you've seen, the previous few lectures
and opening up the credentials file using the usual open construct, cutting the same header inserted
earlier in the previous lecture, because I'll be sending a JSON payload to if this and that.
That's a content type and this is the you are real for the post request.
So the trigger has a name, which is you Python.
This is the name of the event that I have created on if this and that.
I send you to add that in here.
And then after the with a key component of the euro, I pass the efficient that key for my account.
Remember, this is private is going to be different for you than what it is for me.
So you need to get your if this and that key and paste it in here in the credentials file and that makes
up the post.
You are real.
There's no change to the do connect method and lines.
Sixty three, sixty five are identical then I'm not repeating this operation more than one.
So I'm only doing a single post request to the official that every time that I click on the play button,
I don't have a timer to trigger these emails again.
And I'm not using an infinite loop because there's something I want to do.
Only occasionally I'm just going to do it when I actually click on the play button.
So when I click on the play button, the script is going to create those three random dummy sensor values
for temperature, humidity and pressure.
I'll create the Jason document like this by passing those random values across knowledge that have got
value one, value two and value three four the names of these key value pairs.
So these are keys for those values.
So I'm using the same names as the names for the ingredients in the efficient that app.
Or applet, and then in line 80, I'm doing the post request, those requests to post.
And putting the euro ahead, US and the chase and data file waiting for the response to come back and
his response content stored inside the efficient debt, and it's called back variable.
And then I'm simply printing that response to the schill while I wait for that email to arrive in my
email account.
OK, so let's go ahead and try this in practice.
I have already uploaded the efficient credentials file to the tune and I'm going to click on the play
button to execute the script.
OK, try again.
Yeah, does take a couple of times to do this, maybe the security is running something in the background
anyway, so got successful response.
So they try to send through this Jason payload and we got congratulations from if this is that if I
refresh this page, I should see.
Information that my Web hook was successfully.
Received, so there is value one, two and three, so this that these values match with the values that
the authorities did send.
And then have a look at my.
An email.
And she received an email bagenal with this payload as well.
So it was moved things aside, to be able to compare the virus.
So there's temperature 47 degrees, humidity 48.
And Patricia.
64.
I say, OK, so she can see this works quite well.
It is relatively fast as well.
I just did it one more time and.
It's refresh.
The activity page and.
There's a new values, seventy seven for value, three, twenty nine for value, one, forty four for
value two and a copy of the email that was sent out.
See if it's arrived.
And there's an email.
All right, that works, so that's how you can use your especially two with micro python to send out
a notification email via if this.
And then, of course, now that you know how to do that, you'll be able to do many more things in the
efficient that network.
There is one more example in this section that I want to show you, and that is how to get current weather
information for your location or any other location on the planet using the open weather map service.