1
00:00:00,179 --> 00:00:05,359
Great, we are in version two and I'll try
to be quick now and show you version 3.

2
00:00:05,359 --> 00:00:11,370
This is version 3 the way I implemented
this functionality where I want to check

3
00:00:11,370 --> 00:00:17,160
if there is an address column in the
data frame is by adding a try and expect

4
00:00:17,160 --> 00:00:26,400
segment so basically if you can see the
difference is I get the file and then I

5
00:00:26,400 --> 00:00:34,680
try to read that file or this this could
also be outside of the try keywords that

6
00:00:34,680 --> 00:00:39,840
wouldn't be a problem and GC outside of the
try keyword as well. However this is

7
00:00:39,840 --> 00:00:46,140
still better because you may also want
to check for user sending files that

8
00:00:46,140 --> 00:00:51,960
are not csv, so here we're checking
actually that the user is submitting a

9
00:00:51,960 --> 00:00:58,770
CSV file however that only means that
the file has a dot csv extension in the

10
00:00:58,770 --> 00:01:05,309
file name, however that doesn't mean
that the file is actually csv, so you may

11
00:01:05,309 --> 00:01:11,490
have let's say an mp4 file and you have
changed that the extension to csv but

12
00:01:11,490 --> 00:01:17,220
that's still an mp4 file, so what
you want to do is you want to include DF

13
00:01:17,220 --> 00:01:23,850
inside the try and expect block. If Python
is not being able to create a data frame

14
00:01:23,850 --> 00:01:29,460
out of an mp4 file, then it will
throw an error so that's what

15
00:01:29,460 --> 00:01:33,900
actually happens if you pass on an mp4 file.
You wouldn’t be able to read it

16
00:01:33,900 --> 00:01:42,140
as a data frame, so yeah you want to
include that in here and then you return

17
00:01:42,140 --> 00:01:47,390
the same so I haven't changed anything
here, you return the same template

18
00:01:47,390 --> 00:01:54,119
index.html and send the HTML there and the
button, except if there is an error what

19
00:01:54,119 --> 00:01:59,729
you do is you return the index dot HTML but
then instead of the HTML table you want

20
00:01:59,729 --> 00:02:05,369
to return this message and of course you
don't want to return any download

21
00:02:05,369 --> 00:02:10,860
button in there and yeah that should do it.
And that's about version 3 so

22
00:02:10,860 --> 00:02:18,540
those are, those were the differences.
Now version 4, what I have there? Well if you

23
00:02:18,540 --> 00:02:26,100
see here we got this geocoded.csv
file, now that's a string and that means

24
00:02:26,100 --> 00:02:31,200
that a geocoded.csv file will
be created for all the users that will

25
00:02:31,200 --> 00:02:37,650
be submitting data. Now that may cause
some problems because if two users are

26
00:02:37,650 --> 00:02:43,860
submitting data at the same time you may
have some name clashes there. So what did

27
00:02:43,860 --> 00:02:50,070
you do here is you could use a date/time
module to generate unique names for

28
00:02:50,070 --> 00:02:57,090
every generated file and that's what I
did so here is version 4. I imported

29
00:02:57,090 --> 00:03:04,770
the date/time module in here and then
I'm generating the geocoded csv file

30
00:03:04,770 --> 00:03:12,900
in here so DF to csv file name and
I made this fine line global in here

31
00:03:12,900 --> 00:03:20,010
because I also want to access it from
the download function in here, so again I

32
00:03:20,010 --> 00:03:25,200
want to generate that in here I'm
generating a file name and then in the

33
00:03:25,200 --> 00:03:31,080
file name we have the upload string
which will point to the

34
00:03:31,080 --> 00:03:36,900
directory where will this file will be.
Then we have the slash and actually this

35
00:03:36,900 --> 00:03:43,890
plus shouldn't be there so just after
the slash we have the file name and that

36
00:03:43,890 --> 00:03:49,950
would be, you know we have the year, and then
we have the month, and then the day and

37
00:03:49,950 --> 00:03:55,290
then the hour and the minutes, and
seconds, and milliseconds, and then the

38
00:03:55,290 --> 00:04:02,519
dot CSV extension in the file name.
So yeah this is quite unique for every

39
00:04:02,519 --> 00:04:05,810
user because we have milliseconds in
there.

40
00:04:05,810 --> 00:04:13,440
But let me show you how this looks like
actually, so again the user chooses

41
00:04:13,440 --> 00:04:19,200
a file submit and when I press submit
Python will generate that data frame

42
00:04:19,200 --> 00:04:26,760
and it will also generate this
csv file so in this line here and

43
00:04:26,760 --> 00:04:32,310
you can now find that csv file in the
uploads folder so this was this was

44
00:04:32,310 --> 00:04:38,030
generated earlier and this is the file.
That's the file that we just generated.

45
00:04:38,030 --> 00:04:45,150
Then when the user presses download the
file will be downloaded but with your

46
00:04:45,150 --> 00:04:51,510
file name which is this one here.
Yeah, what happens is that the download

47
00:04:51,510 --> 00:04:56,670
function will get the path of the file
that that it has to download in the

48
00:04:56,670 --> 00:05:03,480
browser will get the file name from of
this global variable. that's why I'm

49
00:05:03,480 --> 00:05:08,100
passing this as a global variable so
that I can access the value of it which

50
00:05:08,100 --> 00:05:15,000
is generated in here, I can access this
value from another function and yep

51
00:05:15,000 --> 00:05:20,520
that's my version of the application.
I know this is not like your version.

52
00:05:20,520 --> 00:05:24,930
I hope you are close as much as possible!
I think it would be great if you

53
00:05:24,930 --> 00:05:30,750
you did it better than me. In either case
I'm sure that trying to solve this

54
00:05:30,750 --> 00:05:37,200
application should have improve your
problem-solving skills in Python because

55
00:05:37,200 --> 00:05:42,990
that at least will position you so will
define your level, your Python level so

56
00:05:42,990 --> 00:05:46,020
that you can fill the gaps that you
really think are not your strongest

57
00:05:46,020 --> 00:05:52,000
points. And yeah, that was about this
lecture and I'll see you.

