1 00:00:00,410 --> 00:00:03,284 Great, we are in ver2 and I'll try to 2 00:00:03,285 --> 00:00:05,440 be quick now and show you ver3. 3 00:00:05,970 --> 00:00:08,922 This is ver3 and the way I implemented 4 00:00:08,923 --> 00:00:12,548 this functionality, where I want to check if there 5 00:00:12,549 --> 00:00:14,596 is an address column in the DataFrame, is 6 00:00:14,597 --> 00:00:18,350 by adding a try and expect statement. 7 00:00:19,090 --> 00:00:22,266 So basically, if you can see the difference is, 8 00:00:22,267 --> 00:00:24,380 [No Audio] 9 00:00:24,381 --> 00:00:28,366 I get the file and then I try to read the file. 10 00:00:28,367 --> 00:00:30,650 [No Audio] 11 00:00:30,651 --> 00:00:33,452 Or this could also be outside of the 12 00:00:33,453 --> 00:00:35,628 try keyword, that wouldn't be a problem and 13 00:00:35,629 --> 00:00:38,910 gc outside of a try keyword as well. 14 00:00:38,911 --> 00:00:43,216 However, this is still better because, you may also want 15 00:00:43,217 --> 00:00:47,094 to check for users sending files that are not csv. 16 00:00:47,095 --> 00:00:50,868 So here we're checking actually that the 17 00:00:50,869 --> 00:00:52,874 user is submitting a csv file. 18 00:00:52,875 --> 00:00:56,420 However, that only means that the file has 19 00:00:56,421 --> 00:00:59,600 a .csv extension in the file name. 20 00:01:00,610 --> 00:01:02,228 However, that doesn't mean that 21 00:01:02,229 --> 00:01:04,554 the file is actually csv. 22 00:01:04,555 --> 00:01:07,304 So you may have, let's say an mp4 23 00:01:07,305 --> 00:01:09,918 file and you have changed that the extension 24 00:01:09,919 --> 00:01:13,326 to csv, but that's still an mp4 file. 25 00:01:13,327 --> 00:01:16,328 So what you want to do is, you want 26 00:01:16,329 --> 00:01:20,450 to include df, inside try and expect block. 27 00:01:20,451 --> 00:01:23,938 If Python is not being able to create a dataframe 28 00:01:23,939 --> 00:01:27,842 out of an mp4 file, then it will throw an error. 29 00:01:27,843 --> 00:01:30,256 So that's what actually happens 30 00:01:30,257 --> 00:01:32,864 if you pass an mp4 file, you wouldn't be 31 00:01:32,865 --> 00:01:35,000 able to read it as a dataframe. 32 00:01:35,550 --> 00:01:38,128 So yeah, you want to include that in here. 33 00:01:38,129 --> 00:01:40,933 Then you return 34 00:01:40,934 --> 00:01:42,933 [No Audio] 35 00:01:42,934 --> 00:01:45,364 the same, so I haven't changed anything here. 36 00:01:45,365 --> 00:01:48,932 You return the same template index.html and you send 37 00:01:48,933 --> 00:01:52,868 the html there and the button. Except, if there is 38 00:01:52,869 --> 00:01:56,533 an error, what you do is you return the index.html, 39 00:01:56,534 --> 00:01:59,768 but then instead of the HTML table, you want 40 00:01:59,769 --> 00:02:03,448 to return this message. And of course, you don't want 41 00:02:03,449 --> 00:02:06,760 to return any download button in there. 42 00:02:07,300 --> 00:02:08,766 And yeah, that should do it. 43 00:02:09,163 --> 00:02:13,618 And that's about ver3. So those were the differences. 44 00:02:13,619 --> 00:02:18,400 Now, version four, what I have there, well, if 45 00:02:18,401 --> 00:02:22,410 you see here, we got this geocoded.csv file. 46 00:02:23,390 --> 00:02:26,800 Now that's a string and that means that, 47 00:02:26,801 --> 00:02:30,192 a geocoded.csv file will be created for 48 00:02:30,193 --> 00:02:32,452 all the users, that will be submitting data. 49 00:02:32,453 --> 00:02:36,772 Now that may cause some problems, because if 50 00:02:36,773 --> 00:02:38,852 two users are submitting data at the same 51 00:02:38,853 --> 00:02:42,770 time, you may have some name clashes there. 52 00:02:42,771 --> 00:02:45,048 So what you could do here is you 53 00:02:45,049 --> 00:02:48,830 could use, a datetime module to generate 54 00:02:48,831 --> 00:02:51,854 unique names for every generated file. 55 00:02:51,855 --> 00:02:52,936 And that's what I did. 56 00:02:52,937 --> 00:02:54,660 So here is ver4. 57 00:02:56,250 --> 00:02:59,820 I imported the datetime module in here and 58 00:02:59,821 --> 00:03:06,460 then, I'm generating the geocoded.csv file in here. 59 00:03:06,461 --> 00:03:11,072 So df to_csv filename. And I made this 60 00:03:11,073 --> 00:03:14,736 filename global in here, because I also want to 61 00:03:14,736 --> 00:03:18,866 access it from the download function in here. 62 00:03:19,184 --> 00:03:21,572 So again, I want to generate that in here. 63 00:03:21,573 --> 00:03:24,452 I'm generating a filename. 64 00:03:24,453 --> 00:03:26,596 Then in the filename we have the 65 00:03:26,597 --> 00:03:30,772 upload string, which will point to the fall 66 00:03:30,773 --> 00:03:33,433 to the directory, where this file will be. 67 00:03:33,910 --> 00:03:35,410 Then we have the slash. 68 00:03:35,990 --> 00:03:38,500 And actually, this plus shouldn't be there. 69 00:03:39,590 --> 00:03:42,660 So just after the slash, we have the filename. 70 00:03:43,270 --> 00:03:48,124 And that would, you know, we have year, and then we 71 00:03:48,125 --> 00:03:50,428 have the month, and then the day, and then the 72 00:03:50,429 --> 00:03:54,940 hour, and the minutes and seconds and milliseconds, and then 73 00:03:54,941 --> 00:03:59,470 the .csv extension in the filename. 74 00:03:59,471 --> 00:04:02,672 So, yeah, this is quite unique for every 75 00:04:02,673 --> 00:04:05,820 user, because we have milliseconds in there. 76 00:04:06,430 --> 00:04:09,260 But let me show you how this looks like, actually. 77 00:04:10,450 --> 00:04:14,698 So, again, the user chooses a file, Submit. 78 00:04:14,699 --> 00:04:19,333 And when I press Submit, Python will generate that dataframe, 79 00:04:19,334 --> 00:04:23,410 and it will also generate this csv file. 80 00:04:24,070 --> 00:04:27,128 So in this line here. And you can now 81 00:04:27,129 --> 00:04:30,130 find that csv file in the uploads folder. 82 00:04:30,870 --> 00:04:36,018 So this was generated earlier, and this is the file. 83 00:04:36,019 --> 00:04:38,594 That's the file that we just generated. 84 00:04:38,595 --> 00:04:42,812 Then when the user presses Download, that 85 00:04:42,813 --> 00:04:45,196 file will be downloaded, but with your 86 00:04:45,197 --> 00:04:47,880 filename, which is this one here. 87 00:04:48,970 --> 00:04:52,224 And, yeah, what happens is that the download function 88 00:04:52,225 --> 00:04:55,216 will get the path of the file that, it 89 00:04:55,217 --> 00:04:57,968 has to download in the browser, will get the 90 00:04:57,969 --> 00:05:01,930 filename from this global variable. 91 00:05:02,670 --> 00:05:04,404 That's why I am passing this as a 92 00:05:04,405 --> 00:05:07,172 global variable, so that I can access the 93 00:05:07,173 --> 00:05:09,860 value of it, which is generated in here. 94 00:05:09,861 --> 00:05:13,140 I can access this value from another function. 95 00:05:13,830 --> 00:05:17,900 And, yeah, that's my version of the application. 96 00:05:18,630 --> 00:05:20,830 I know this is not like your version. 97 00:05:20,831 --> 00:05:24,616 I hope you were close, as much as possible. It would be great, 98 00:05:24,617 --> 00:05:26,133 if you did it better than me. 99 00:05:26,890 --> 00:05:30,578 In either case, I'm sure that, trying to solve 100 00:05:30,579 --> 00:05:35,874 this application should have improved your problem solving skills 101 00:05:35,875 --> 00:05:39,484 in Python, because that at least will position you, 102 00:05:39,485 --> 00:05:42,908 so will define your level, your Python level, so 103 00:05:42,909 --> 00:05:44,572 that you can fill the gaps, that you really 104 00:05:44,573 --> 00:05:46,920 think, are not your strongest points. 105 00:05:47,770 --> 00:05:49,506 And, yeah, that was about this lecture. 106 00:05:49,507 --> 00:05:51,266 And I'll see you.