Great, we are in ver2 and I'll try to
be quick now and show you ver3.
This is ver3 and the way I implemented
this functionality, where I want to check if there
is an address column in the DataFrame, is
by adding a try and expect statement.
So basically, if you can see the difference is,
[No Audio]
I get the file and then I try to read the file.
[No Audio]
Or this could also be outside of the
try keyword, that wouldn't be a problem and
gc outside of a try keyword as well.
However, this is still better because, you may also want
to check for users sending files that are not csv.
So here we're checking actually that the
user is submitting a csv file.
However, that only means that the file has
a .csv extension in the file name.
However, that doesn't mean that
the file is actually csv.
So you may have, let's say an mp4
file and you have changed that the extension
to csv, but that's still an mp4 file.
So what you want to do is, you want
to include df, inside try and expect block.
If Python is not being able to create a dataframe
out of an mp4 file, then it will throw an error.
So that's what actually happens
if you pass an mp4 file, you wouldn't be
able to read it as a dataframe.
So yeah, you want to include that in here.
Then you return
[No Audio]
the same, so I haven't changed anything here.
You return the same template index.html and you send
the html there and the button. Except, if there is
an error, what you do is you return the index.html,
but then instead of the HTML table, you want
to return this message. And of course, you don't want
to return any download button in there.
And yeah, that should do it.
And that's about ver3. So those were the differences.
Now, version four, what I have there, well, if
you see here, we got this geocoded.csv file.
Now that's a string and that means that,
a geocoded.csv file will be created for
all the users, that will be submitting data.
Now that may cause some problems, because if
two users are submitting data at the same
time, you may have some name clashes there.
So what you could do here is you
could use, a datetime module to generate
unique names for every generated file.
And that's what I did.
So here is ver4.
I imported the datetime module in here and
then, I'm generating the geocoded.csv file in here.
So df to_csv filename. And I made this
filename global in here, because I also want to
access it from the download function in here.
So again, I want to generate that in here.
I'm generating a filename.
Then in the filename we have the
upload string, which will point to the fall
to the directory, where this file will be.
Then we have the slash.
And actually, this plus shouldn't be there.
So just after the slash, we have the filename.
And that would, you know, we have year, and then we
have the month, and then the day, and then the
hour, and the minutes and seconds and milliseconds, and then
the .csv extension in the filename.
So, yeah, this is quite unique for every
user, because we have milliseconds in there.
But let me show you how this looks like, actually.
So, again, the user chooses a file, Submit.
And when I press Submit, Python will generate that dataframe,
and it will also generate this csv file.
So in this line here. And you can now
find that csv file in the uploads folder.
So this was generated earlier, and this is the file.
That's the file that we just generated.
Then when the user presses Download, that
file will be downloaded, but with your
filename, which is this one here.
And, yeah, what happens is that the download function
will get the path of the file that, it
has to download in the browser, will get the
filename from this global variable.
That's why I am passing this as a
global variable, so that I can access the
value of it, which is generated in here.
I can access this value from another function.
And, yeah, that's my version of the application.
I know this is not like your version.
I hope you were close, as much as possible. It would be great,
if you did it better than me.
In either case, I'm sure that, trying to solve
this application should have improved your problem solving skills
in Python, because that at least will position you,
so will define your level, your Python level, so
that you can fill the gaps, that you really
think, are not your strongest points.
And, yeah, that was about this lecture.
And I'll see you.