1
00:00:00,720 --> 00:00:03,630
Narrator: To create a useful rain alert application.

2
00:00:03,630 --> 00:00:04,920
We want our script

3
00:00:04,920 --> 00:00:08,640
to detect if it will rain within the next 12 hours

4
00:00:08,640 --> 00:00:11,130
of the Python script being run.

5
00:00:11,130 --> 00:00:13,680
Let's say every day you leave your home at 8:00 AM

6
00:00:13,680 --> 00:00:15,150
in order to go to work,

7
00:00:15,150 --> 00:00:18,990
then by 5:00 or 6:00 PM you might be done with work

8
00:00:18,990 --> 00:00:21,240
and on your way back home.

9
00:00:21,240 --> 00:00:24,000
Given that the free OpenWeatherMap API

10
00:00:24,000 --> 00:00:27,990
gives us the weather forecast in three hour intervals,

11
00:00:27,990 --> 00:00:30,120
we can run the script at 6:00 AM

12
00:00:30,120 --> 00:00:33,240
and check the weather for the next 12 hours.

13
00:00:33,240 --> 00:00:34,560
If there's rain forecast

14
00:00:34,560 --> 00:00:36,690
during the time you're away from home,

15
00:00:36,690 --> 00:00:39,630
you want your Python script to send you a text message,

16
00:00:39,630 --> 00:00:42,060
reminding you to bring an umbrella.

17
00:00:42,060 --> 00:00:45,270
That way you'll get notified before you leave home

18
00:00:45,270 --> 00:00:47,133
and know how to prepare for the day.

19
00:00:48,450 --> 00:00:50,700
In the previous lesson, we saw that the data

20
00:00:50,700 --> 00:00:53,010
that we got back from OpenWeatherMap

21
00:00:53,010 --> 00:00:55,830
contains the weather forecast every three hours

22
00:00:55,830 --> 00:00:57,720
for the next five days.

23
00:00:57,720 --> 00:01:00,960
There are forecasts for 40 different timestamps,

24
00:01:00,960 --> 00:01:04,950
starting from zero and going up all the way to 39.

25
00:01:04,950 --> 00:01:07,650
Now, I dunno about you, but my decision

26
00:01:07,650 --> 00:01:09,420
whether or not to bring an umbrella

27
00:01:09,420 --> 00:01:11,640
really only depends on the forecast

28
00:01:11,640 --> 00:01:13,530
for the next 12 hours.

29
00:01:13,530 --> 00:01:16,410
In the JSON that we got back from OpenWeatherMap,

30
00:01:16,410 --> 00:01:20,250
that would be only the first four forecasts in the list.

31
00:01:20,250 --> 00:01:22,410
If the script is run at 6:00 AM

32
00:01:22,410 --> 00:01:26,520
then a 12-hour window takes us up to 6:00 PM

33
00:01:26,520 --> 00:01:29,430
by which time, we're hopefully ready to head home

34
00:01:29,430 --> 00:01:30,480
and we don't need to worry

35
00:01:30,480 --> 00:01:32,793
if it starts raining much later than that.

36
00:01:33,690 --> 00:01:36,180
If we look at this JSON that we got back,

37
00:01:36,180 --> 00:01:38,550
we don't actually care about the forecasts

38
00:01:38,550 --> 00:01:42,300
that are for tomorrow or those even further in the future.

39
00:01:42,300 --> 00:01:43,650
We just care about the weather

40
00:01:43,650 --> 00:01:46,290
within the next four forecasts.

41
00:01:46,290 --> 00:01:49,260
Looking at the API documentation more closely,

42
00:01:49,260 --> 00:01:51,330
we can actually spot parameters

43
00:01:51,330 --> 00:01:55,140
that will help us to tailor OpenWeatherMaps response,

44
00:01:55,140 --> 00:01:56,850
so that we just get back the data

45
00:01:56,850 --> 00:01:58,590
that we actually care about.

46
00:01:58,590 --> 00:02:03,590
Of course, I'm talking about the cnt or count parameter.

47
00:02:03,660 --> 00:02:06,330
By setting the count to four,

48
00:02:06,330 --> 00:02:09,090
we'll request only four timestamps

49
00:02:09,090 --> 00:02:12,540
covering the 12-hour window that matters to us.

50
00:02:12,540 --> 00:02:14,820
That way we make our own lives easier

51
00:02:14,820 --> 00:02:18,240
and we avoid requesting more data than we actually need.

52
00:02:18,240 --> 00:02:20,550
That's why it's always a good idea to have a read

53
00:02:20,550 --> 00:02:24,000
through the API documentation first.

54
00:02:24,000 --> 00:02:25,950
There are usually some useful nuggets in there

55
00:02:25,950 --> 00:02:29,700
that will make your life as a developer much, much easier.

56
00:02:29,700 --> 00:02:31,530
As I always say, this is like going

57
00:02:31,530 --> 00:02:33,120
into somebody else's house.

58
00:02:33,120 --> 00:02:34,260
Everything is different.

59
00:02:34,260 --> 00:02:36,780
The way that the washing machine works is different.

60
00:02:36,780 --> 00:02:39,060
The way that their dryer works is different.

61
00:02:39,060 --> 00:02:40,440
So you really have

62
00:02:40,440 --> 00:02:43,590
to look at the API documentation when you are working

63
00:02:43,590 --> 00:02:46,380
with a new API, just so that you're not caught out

64
00:02:46,380 --> 00:02:49,170
and you understand exactly what you have to do

65
00:02:49,170 --> 00:02:52,053
in order to be a good API user.

66
00:02:53,370 --> 00:02:55,890
Now, let's go back into our Python code

67
00:02:55,890 --> 00:02:58,350
and provide that extra parameter.

68
00:02:58,350 --> 00:03:00,240
The parameter was called count,

69
00:03:00,240 --> 00:03:04,110
and I'll just add it to our weather_params dictionary.

70
00:03:04,110 --> 00:03:05,730
Let's set count to four,

71
00:03:05,730 --> 00:03:09,630
so that we request only the timestamps in the near future.

72
00:03:09,630 --> 00:03:14,490
Let's run it again and take a look at the JSON response

73
00:03:14,490 --> 00:03:15,810
we get back.

74
00:03:15,810 --> 00:03:17,190
I'm going to copy it again,

75
00:03:17,190 --> 00:03:19,590
go back to the online JSON viewer,

76
00:03:19,590 --> 00:03:22,530
clear that huge amount of data from before

77
00:03:22,530 --> 00:03:24,750
and paste in what I just got back.

78
00:03:24,750 --> 00:03:26,880
You can already see it's much shorter

79
00:03:26,880 --> 00:03:29,580
and if I click on Viewer, we can see that our list

80
00:03:29,580 --> 00:03:31,920
of weather forecasts now only contain

81
00:03:31,920 --> 00:03:33,993
the next four timestamps.

82
00:03:35,070 --> 00:03:36,480
So that's the goal.

83
00:03:36,480 --> 00:03:39,360
And if we head back into our code,

84
00:03:39,360 --> 00:03:42,180
we know that at the moment the response code

85
00:03:42,180 --> 00:03:45,900
that we're getting back from calling this API is 200.

86
00:03:45,900 --> 00:03:47,520
So it's successful.

87
00:03:47,520 --> 00:03:48,750
But we wanna make sure

88
00:03:48,750 --> 00:03:51,900
that we actually catch other response codes.

89
00:03:51,900 --> 00:03:54,750
So we're going to call raise_for_status,

90
00:03:54,750 --> 00:03:57,150
so that if there is a problem

91
00:03:57,150 --> 00:03:59,220
and we don't get a 200 code,

92
00:03:59,220 --> 00:04:01,293
then we actually raise an exception.

93
00:04:02,400 --> 00:04:06,450
Now, next, we wanna save our response.json

94
00:04:06,450 --> 00:04:07,840
as the weather_data

95
00:04:09,480 --> 00:04:11,040
and then we're gonna work with this data

96
00:04:11,040 --> 00:04:13,380
in order to get the particular pieces

97
00:04:13,380 --> 00:04:14,630
that we're interested in.

98
00:04:15,600 --> 00:04:17,519
That's step one done.

99
00:04:17,519 --> 00:04:21,899
The next step is to dig through this hourly forecast

100
00:04:21,899 --> 00:04:24,750
and get hold of the thing that we're interested in,

101
00:04:24,750 --> 00:04:28,170
which is the actual weather condition.

102
00:04:28,170 --> 00:04:30,390
The way that weather services tend

103
00:04:30,390 --> 00:04:34,290
to provide the weather condition is through an id.

104
00:04:34,290 --> 00:04:38,730
And I know this because I read the API documentation.

105
00:04:38,730 --> 00:04:42,630
It's not because I'm some sort of weather geek. (laughs)

106
00:04:42,630 --> 00:04:45,930
Although, I mean that's not a bad thing to be I guess.

107
00:04:45,930 --> 00:04:50,930
If we scroll down in this documentation past the examples,

108
00:04:51,000 --> 00:04:53,010
you can see it provides all of the fields

109
00:04:53,010 --> 00:04:54,600
in the API response.

110
00:04:54,600 --> 00:04:56,280
So these are all of the things

111
00:04:56,280 --> 00:04:59,760
that we could possibly get back and what they mean.

112
00:04:59,760 --> 00:05:01,920
And you can see there's some really interesting things,

113
00:05:01,920 --> 00:05:05,250
like what does the temperature feel like based

114
00:05:05,250 --> 00:05:08,850
on the wind chill and actual ground temperature.

115
00:05:08,850 --> 00:05:13,020
But what we're mostly interested in is the weather data.

116
00:05:13,020 --> 00:05:18,020
So this weather id is a weather condition id,

117
00:05:18,480 --> 00:05:21,660
and when you click on that link, it takes you to this table

118
00:05:21,660 --> 00:05:24,750
that shows you all of the weather condition codes

119
00:05:24,750 --> 00:05:29,103
that we could possibly get back in this particular field.

120
00:05:30,030 --> 00:05:31,860
Now, you can see that all the codes

121
00:05:31,860 --> 00:05:36,860
that start off with 2 means some sort of thunderstorm.

122
00:05:37,230 --> 00:05:38,730
And then starting with 3,

123
00:05:38,730 --> 00:05:40,380
that means some sort of drizzling.

124
00:05:40,380 --> 00:05:42,450
Starting with 5 means rain.

125
00:05:42,450 --> 00:05:44,550
Starting with 6 means snow.

126
00:05:44,550 --> 00:05:47,460
And then afterwards we have the seven hundreds.

127
00:05:47,460 --> 00:05:50,340
So these are atmospheric things like a bit of mist,

128
00:05:50,340 --> 00:05:53,040
a bit of smoke, a bit of dust or fog.

129
00:05:53,040 --> 00:05:55,920
And this is also incidentally the reason why

130
00:05:55,920 --> 00:06:00,000
this weather key actually has a value

131
00:06:00,000 --> 00:06:02,070
that's in the form of a list.

132
00:06:02,070 --> 00:06:05,250
You can see that's denoted by the square brackets here.

133
00:06:05,250 --> 00:06:08,730
So there could actually be multiple weather conditions

134
00:06:08,730 --> 00:06:12,180
for a particular place at a particular hour

135
00:06:12,180 --> 00:06:16,020
and that's because you could maybe have snow,

136
00:06:16,020 --> 00:06:18,753
but you could also have fog at the same time.

137
00:06:19,740 --> 00:06:22,260
Now, when I looked through a lot of the examples

138
00:06:22,260 --> 00:06:26,010
and the documentation, it seems like the first item

139
00:06:26,010 --> 00:06:28,710
in that list is the main condition.

140
00:06:28,710 --> 00:06:30,030
So if it's gonna rain,

141
00:06:30,030 --> 00:06:32,160
then it's gonna be in that first item

142
00:06:32,160 --> 00:06:35,070
in the list of weather conditions.

143
00:06:35,070 --> 00:06:39,630
Inside that list, we have a dictionary or many dictionaries.

144
00:06:39,630 --> 00:06:42,870
Each of those contain a weather condition id,

145
00:06:42,870 --> 00:06:46,260
the main condition name and the description.

146
00:06:46,260 --> 00:06:49,410
So if we look at this id code 802,

147
00:06:49,410 --> 00:06:51,780
we can decode it in this table

148
00:06:51,780 --> 00:06:54,540
and you can see it means scattered clouds.

149
00:06:54,540 --> 00:06:57,903
20 to 50% of the sky is covered in clouds, basically.

150
00:06:59,370 --> 00:07:01,500
Based on this list, we can say that,

151
00:07:01,500 --> 00:07:05,550
well, anything that has a code less than 700,

152
00:07:05,550 --> 00:07:08,730
then we probably will need an umbrella.

153
00:07:08,730 --> 00:07:11,400
I'm not sure how you stand on the umbrella

154
00:07:11,400 --> 00:07:15,180
in snow situation, but I personally do like

155
00:07:15,180 --> 00:07:17,130
to hold an umbrella when it's snowing,

156
00:07:17,130 --> 00:07:18,780
especially because I live in a country

157
00:07:18,780 --> 00:07:22,130
where the snow is not crazy, it's just sort of...

158
00:07:23,220 --> 00:07:26,670
It's never sort of the beautiful snow

159
00:07:26,670 --> 00:07:29,310
where it's thick and it gets caught on your eyelashes.

160
00:07:29,310 --> 00:07:33,810
It's the sort of annoying slush that's just sort of snow,

161
00:07:33,810 --> 00:07:37,380
but it's sort of like somebody spitting at you.

162
00:07:37,380 --> 00:07:38,940
In my case, I would prefer

163
00:07:38,940 --> 00:07:41,820
to have an umbrella if it was gonna snow.

164
00:07:41,820 --> 00:07:44,040
I'm going to check for the codes

165
00:07:44,040 --> 00:07:47,010
that we get back from the OpenWeatherMap API,

166
00:07:47,010 --> 00:07:49,890
and if the code is less than 700,

167
00:07:49,890 --> 00:07:53,553
then I'm gonna advise my user to bring an umbrella.

168
00:07:55,290 --> 00:07:57,690
Here's a challenge for you.

169
00:07:57,690 --> 00:08:00,150
Can you figure out how to look

170
00:08:00,150 --> 00:08:01,800
through the data that we get back,

171
00:08:01,800 --> 00:08:05,073
which remember looks something like this,

172
00:08:05,910 --> 00:08:08,910
and then look at the weather

173
00:08:08,910 --> 00:08:13,410
and the first item in the weather list and also the id?

174
00:08:13,410 --> 00:08:16,800
So you're going to go all the way down to this,

175
00:08:16,800 --> 00:08:19,830
but remember you're gonna do that for all of the items

176
00:08:19,830 --> 00:08:22,410
and you're going to check for the condition code.

177
00:08:22,410 --> 00:08:26,700
Now if any of those id codes are less than 700,

178
00:08:26,700 --> 00:08:30,330
then you want to be able to print out, bring an umbrella.

179
00:08:30,330 --> 00:08:32,340
So that's the goal

180
00:08:32,340 --> 00:08:35,460
and the actual implementation, I'll leave up to you

181
00:08:35,460 --> 00:08:37,799
'cause there's quite a few ways that you can do this,

182
00:08:37,799 --> 00:08:40,710
but I'm sure by now, you are well prepared

183
00:08:40,710 --> 00:08:44,400
with all of your tools in Python to figure this out.

184
00:08:44,400 --> 00:08:48,180
If you wanna make sure that your code is actually working,

185
00:08:48,180 --> 00:08:50,730
you can switch to a latitude and longitude

186
00:08:50,730 --> 00:08:52,860
that is definitely raining.

187
00:08:52,860 --> 00:08:56,130
So if you go to ventusky.com,

188
00:08:56,130 --> 00:08:59,340
they actually show you the live weather forecast.

189
00:08:59,340 --> 00:09:03,270
So we can look at precipitation, which is basically rain,

190
00:09:03,270 --> 00:09:06,000
and we can find some sort of unfortunate place,

191
00:09:06,000 --> 00:09:09,060
which seems to be really heavily raining.

192
00:09:09,060 --> 00:09:11,313
For example, this place in Poland, Lodz,

193
00:09:12,270 --> 00:09:16,145
and if I spell that name correctly.

194
00:09:16,145 --> 00:09:19,200
(keyboard typing)

195
00:09:19,200 --> 00:09:22,560
Lodz and then I'll add the country code Poland

196
00:09:22,560 --> 00:09:24,750
and just to make sure in the map,

197
00:09:24,750 --> 00:09:27,510
it's actually found the correct place.

198
00:09:27,510 --> 00:09:29,280
Yet that looks pretty much it,

199
00:09:29,280 --> 00:09:32,310
then I can switch out my latitude and longitude

200
00:09:32,310 --> 00:09:34,260
with this rainy place

201
00:09:34,260 --> 00:09:37,470
and that way I know that at least one of the results

202
00:09:37,470 --> 00:09:39,480
I get back is definitely going

203
00:09:39,480 --> 00:09:41,463
to contain some sort of rain.

204
00:09:44,400 --> 00:09:46,620
Now if we look at their hourly data,

205
00:09:46,620 --> 00:09:48,450
you can see that the weather

206
00:09:48,450 --> 00:09:51,780
is basically just rain, rain, rain.

207
00:09:51,780 --> 00:09:55,020
So between looking at places which are sunny

208
00:09:55,020 --> 00:09:58,020
and places which are rainy, you should be able

209
00:09:58,020 --> 00:09:59,370
to get your code to work,

210
00:09:59,370 --> 00:10:02,610
so that it tells you in the next 12 hours,

211
00:10:02,610 --> 00:10:07,350
if any of those condition codes are less than 700,

212
00:10:07,350 --> 00:10:10,263
which means it's got some form of precipitation.

213
00:10:11,310 --> 00:10:13,173
Pause the video and give this a go.

214
00:10:18,300 --> 00:10:22,290
All right, so let's narrow down into this weather.

215
00:10:22,290 --> 00:10:24,090
If we want to get the weather,

216
00:10:24,090 --> 00:10:28,320
then we have to tap into the first item in our list

217
00:10:28,320 --> 00:10:30,030
and then we get hold of the weather

218
00:10:30,030 --> 00:10:32,010
and then we get hold of the first item

219
00:10:32,010 --> 00:10:37,010
in that list under the id key, we'll get the actual value.

220
00:10:37,050 --> 00:10:40,050
We've talked about this in detail in previous lessons.

221
00:10:40,050 --> 00:10:42,030
If you've skipped a lot of lessons

222
00:10:42,030 --> 00:10:43,860
and you've come here directly,

223
00:10:43,860 --> 00:10:46,050
then it's gonna be a little bit confusing

224
00:10:46,050 --> 00:10:48,630
and I recommend to review the previous lessons

225
00:10:48,630 --> 00:10:50,580
before you continue.

226
00:10:50,580 --> 00:10:53,820
Instead of printing the weather data, let's drill down.

227
00:10:53,820 --> 00:10:56,250
Let's get to the first item here.

228
00:10:56,250 --> 00:10:58,650
If we provide a set of square brackets

229
00:10:58,650 --> 00:11:00,630
and then we can access the value

230
00:11:00,630 --> 00:11:04,500
inside the list key, like this.

231
00:11:04,500 --> 00:11:08,910
And now, we've got a list with all of the hourly data

232
00:11:08,910 --> 00:11:11,613
and it looks pretty much like this.

233
00:11:12,780 --> 00:11:14,250
Now, you can confirm this

234
00:11:14,250 --> 00:11:17,790
by also pasting this into the JSON viewer,

235
00:11:17,790 --> 00:11:20,460
replacing the previous text that was there.

236
00:11:20,460 --> 00:11:24,330
You can see we now have our items in this list.

237
00:11:24,330 --> 00:11:25,650
To drill further down,

238
00:11:25,650 --> 00:11:28,260
let's get hold of the first item in that list

239
00:11:28,260 --> 00:11:30,960
by providing a square bracket

240
00:11:30,960 --> 00:11:33,990
and then the index, which is zero.

241
00:11:33,990 --> 00:11:36,660
Now, we are into the first item

242
00:11:36,660 --> 00:11:39,120
and this is what the data looks like.

243
00:11:39,120 --> 00:11:40,980
It's a lot shorter.

244
00:11:40,980 --> 00:11:44,820
Now, we wanna tap into the weather condition,

245
00:11:44,820 --> 00:11:47,340
so that means yet another set of square brackets

246
00:11:47,340 --> 00:11:50,823
and then the name of the key, which is weather.

247
00:11:52,560 --> 00:11:53,730
Now, it's pretty simple.

248
00:11:53,730 --> 00:11:58,470
It's simply giving us a list with only one item.

249
00:11:58,470 --> 00:12:02,820
Let's tap into that one item by using again,

250
00:12:02,820 --> 00:12:05,070
square brackets, zero.

251
00:12:05,070 --> 00:12:10,070
And now, we've got just a simple dictionary, essentially.

252
00:12:10,470 --> 00:12:12,330
So if we wanna get hold of the id,

253
00:12:12,330 --> 00:12:15,570
then it's the final square bracket

254
00:12:15,570 --> 00:12:18,450
and the key, which is id.

255
00:12:18,450 --> 00:12:21,690
Now, what if I created a new list

256
00:12:21,690 --> 00:12:24,600
that contains the condition codes?

257
00:12:24,600 --> 00:12:26,610
We know that we've got a list

258
00:12:26,610 --> 00:12:31,470
of all of the weather conditions for the next 12 hours.

259
00:12:31,470 --> 00:12:36,470
How can we loop through that list to find out the actual id

260
00:12:36,780 --> 00:12:39,873
of the weather condition for each of those hours?

261
00:12:40,770 --> 00:12:42,570
Well, we can create a for loop

262
00:12:42,570 --> 00:12:46,590
that looks at each of the data from the hour.

263
00:12:46,590 --> 00:12:50,640
So for hour_data in weather_data list,

264
00:12:50,640 --> 00:12:53,070
so this is gonna go through the 12 hours.

265
00:12:53,070 --> 00:12:56,220
And then for each, we're going to tap into the hour data

266
00:12:56,220 --> 00:12:58,830
and try to get hold of the item

267
00:12:58,830 --> 00:13:01,653
that is in the weather key.

268
00:13:03,510 --> 00:13:04,413
Like this.

269
00:13:05,370 --> 00:13:09,180
Now, I'm going to print each of these

270
00:13:09,180 --> 00:13:12,360
and you can see, we've now got a list

271
00:13:12,360 --> 00:13:17,360
of all of the weather conditions for each of those hours.

272
00:13:17,760 --> 00:13:20,790
Now, let's narrow down that a little bit further.

273
00:13:20,790 --> 00:13:24,300
Let's get hold of the first item of each of these lists.

274
00:13:24,300 --> 00:13:26,580
And you can see, in fact, there's only one item

275
00:13:26,580 --> 00:13:27,930
in all of these lists.

276
00:13:27,930 --> 00:13:31,200
It's very rare that you have multiple weather conditions

277
00:13:31,200 --> 00:13:32,463
for each hour.

278
00:13:33,420 --> 00:13:36,420
Now that gives us a Python dictionary

279
00:13:36,420 --> 00:13:38,100
for each of those hours

280
00:13:38,100 --> 00:13:41,310
and we can tap into that final value we're interested in

281
00:13:41,310 --> 00:13:43,800
under the key id.

282
00:13:43,800 --> 00:13:47,760
So now, we've looped through the next 12 hours

283
00:13:47,760 --> 00:13:51,810
and got hold of the weather condition id

284
00:13:51,810 --> 00:13:53,223
for each of those hours.

285
00:13:54,120 --> 00:13:57,870
Now, all we need to do is to save this

286
00:13:57,870 --> 00:14:02,870
instead of printing it and we'll call it the condition_code.

287
00:14:02,871 --> 00:14:06,270
(keyboard typing)

288
00:14:06,270 --> 00:14:07,710
And remember previously we said

289
00:14:07,710 --> 00:14:11,340
that if the condition code is less than 700,

290
00:14:11,340 --> 00:14:15,000
then we're going to print, bring an umbrella.

291
00:14:15,000 --> 00:14:17,940
So we can check if condition_code,

292
00:14:17,940 --> 00:14:21,540
which remember at this point is still a string.

293
00:14:21,540 --> 00:14:25,350
So we have to turn that into an integer

294
00:14:25,350 --> 00:14:29,010
in order to be able to compare it against another number.

295
00:14:29,010 --> 00:14:33,570
If that condition_code as an integer is less than 700,

296
00:14:33,570 --> 00:14:37,173
then we're going to print, bring an umbrella.

297
00:14:39,510 --> 00:14:42,420
And you can see that for the next 12 hours,

298
00:14:42,420 --> 00:14:46,470
there's rain at this particular place in Lodz in Poland

299
00:14:46,470 --> 00:14:49,860
that I've put into the latitude and longitude.

300
00:14:49,860 --> 00:14:51,270
Now, if I don't want

301
00:14:51,270 --> 00:14:54,720
to call this print statement many times,

302
00:14:54,720 --> 00:14:57,718
then we can define a variable outside the for loop

303
00:14:57,718 --> 00:14:59,135
called will_rain,

304
00:15:00,000 --> 00:15:03,180
and we can set that to false to begin with.

305
00:15:03,180 --> 00:15:06,570
Now if during the next 12 hours the condition_code

306
00:15:06,570 --> 00:15:08,310
is less than 700,

307
00:15:08,310 --> 00:15:12,540
then we'll switch that to equal true instead.

308
00:15:12,540 --> 00:15:16,140
Now, after the for loop has completed,

309
00:15:16,140 --> 00:15:17,850
then we can check to see

310
00:15:17,850 --> 00:15:20,130
if it will_rain in the next 12 hours.

311
00:15:20,130 --> 00:15:22,503
And if so, it will print, bring an umbrella.

312
00:15:23,760 --> 00:15:26,790
This way we'll only get one print statement being called,

313
00:15:26,790 --> 00:15:28,560
instead of every single time

314
00:15:28,560 --> 00:15:32,280
we land on a condition_code for rain.

315
00:15:32,280 --> 00:15:36,330
So this involved quite a bit of JSON passing

316
00:15:36,330 --> 00:15:41,330
and also understanding how to work with parameters and APIs.

317
00:15:41,970 --> 00:15:44,490
Now, I hope you managed to get this far by yourself,

318
00:15:44,490 --> 00:15:47,370
but if not, be sure to review what I've written

319
00:15:47,370 --> 00:15:49,710
and fix your code as required.

320
00:15:49,710 --> 00:15:51,330
If any of it was confusing,

321
00:15:51,330 --> 00:15:54,570
be sure to review previous lessons before you continue

322
00:15:54,570 --> 00:15:56,340
because we're now building heavily

323
00:15:56,340 --> 00:15:57,870
on your previous knowledge

324
00:15:57,870 --> 00:16:00,390
that you learned through the course.

325
00:16:00,390 --> 00:16:01,800
Now, in the next lesson,

326
00:16:01,800 --> 00:16:03,930
we're gonna be looking at how we can,

327
00:16:03,930 --> 00:16:06,600
instead of printing, bring an umbrella

328
00:16:06,600 --> 00:16:09,870
to send a SMS text message

329
00:16:09,870 --> 00:16:12,993
that notifies you to bring an umbrella instead.

330
00:16:13,860 --> 00:16:15,960
So for all of that and more,

331
00:16:15,960 --> 00:16:17,560
I'll see you on the next lesson.

