Placeholder Image

字幕表 動画を再生する

  • all right, so it's time for a one day build again.

  • It's been a long time since actually did one last time.

  • I think it's been like five, maybe six weeks s.

  • It's been way too long, I think.

  • But it's time to get back into them.

  • And what we're gonna do today is we're going to basically create a quite on script slash kind of a shell script, and we're gonna automate the process of taking notes because right now what I use is ever note and what I have to do is have to open up every note.

  • I have to go into it and look through all the notebooks, find the right one, go into that and then open up a new note inside that, and I kind of want to speed that process up.

  • And I spent a lot of time in the terminal.

  • So I figured we're going to create a shelter of command that's essentially gonna create notes for us automatically.

  • So that's what we're doing today.

  • Thanks.

  • What?

  • We're going to start with us just writing out the requirements, and then I'm going to go through a little bit more detail.

  • What I want the app to do, because I don't.

  • I'm not quite clear on the exact requirements, so we're going to start with that as usual.

  • So what the requirements are we need a command for creating the note that that's gonna be the command that we use here in the terminal.

  • And this command should then create a new text file.

  • It should add it in the right directory, and it should.

  • We should also be able to create folders using this command.

  • And then after it's created the file, it should then open the text file in sublime text.

  • The only reason for using sublime text is because that is really my favorite text editor, especially for just simple files like notes and things like that, which is what I'm mostly gonna use the script for.

  • And then it should also be able to create other file types.

  • And then I created another title here called Sequence Slash Process.

  • And this is essentially what the process is gonna look like for the program.

  • What the steps are going to be for the program to take up here.

  • We have all the different commands that we could D'oh.

  • So the 1st 1 is where we spell everything out.

  • We type in first note and then we type in the name of the note comes next.

  • And then after that, we type in the folder and the name of that folder, and then we type in what extension we want to add to it.

  • And then that's the extension.

  • So what I want to do is I also wanna have, like, shorthand commands for all of this stuff.

  • So n f E stands for note folder extension.

  • So then first you type in the note, then you type in the folder name and then you type in the extension, and then you can also just type in note an extension and e any type in the note and the extension.

  • And this would then put a new note in just a folder called General or some like that.

  • Um, And then we have a just end where you just create a new note and that will default to adult text file.

  • And then we have also, uh, the folder.

  • If you just want to create a folder, you can just type in F, and then that would be APS and then after we've typed in the command.

  • Whatever the command ISS, it should navigate to the notes folder, which is gonna be our main folder after its navigated to that folder, it should shake if a folder named AP already exists.

  • And if there's no folder named APP, then it will create a new folder named up and ah, Then I'll navigate into that folder, and then we'll check within that folder.

  • If a file named my notes already exists and if the file exists, then it'll open that file in sublime text.

  • And if it doesn't exist, then it will create the file and then open it up s So that's essentially what I'm thinking that the app is gonna be to start out with No, stop.

  • I go.

  • There we go.

  • We have a new file cold note.

  • Stop, I So what we want to do now is we want to be able to access the different arguments that we pass into the script.

  • All right, I'll start by just creating the shell script part of this app, and then we'll get into creating the actual python part of it.

  • Yeah, So we're gonna start with that, so I just want to mention that today's video is actually sponsored by hosting her, which is the hosting platform that I'm currently using for my website on Blawg.

  • And it's a platform that works really well and it feels really modern and has super easy integration with WordPress.

  • All you need to do is open your hosting control panel and then into your details and click one button to install WordPress, and I've actually used a few.

  • Other service is for hosting in the past, and I've found that hosting is by far the easiest to use.

  • A couple reasons for this is that they have super simple and clean you.

  • I would just hope that I really like they have really fast load times, and they have 24 7 customer support.

  • It's just really good, which is why I personally use them and why I can also 100% recommend them to you guys.

  • So if you just go to hosting a dot com slash cow and then use the coupon code cal with capital letters, you will get up to 91% off your yearly went posting plants.

  • All right, so now this is done Now we need to make sure that this Python script runs in the correct way.

  • So that's what we're gonna do now.

  • Now I'm able to actually get all of the arguments that we want.

  • So if we type in note and then the name of the note and then folder and the name of the folder and then extension and then the extension, then we get all of them printed out like this so we can see the name of the note, the name of the folder and the name of the extension as well s.

  • So that's really good.

  • The only thing is that it doesn't really matter what you type in here, and it doesn't matter what you type in here.

  • I could type in anything and it'll still print the same things.

  • I don't know if I like that.

  • Okay, so maybe we should just do something like this where just says NFI, and that's note, folder and extension.

  • And then you just type in the name of the note in the name of the folder and the name of the extension.

  • I think that's going to be better, because I think it looks better.

  • It's easier to type out as well.

  • All right, so right now we're able to create a new file and we're able to type in the name of that file a swell we're not able to create a folder.

  • Were not able to add the extension.

  • Actually, adding the extension is pretty simple.

  • We could just d'oh all right now where we should be able to add the extension as well.

  • Right?

  • So the next thing that we're going to try to do is Thio pass a command to the Python script to open up sublime text and this file that we create think this should work now if we type in the command, which is N f a.

  • Right there we go.

  • So that opened up the note in sublime text for us.

  • So that's the first step essentially done for us.

  • Now comes the file organization.

  • So that's gonna be the next step.

  • Is Thio first of all, navigate to the right place, create the file in the right place.

  • So what I've done now is I've made it so that it navigates back to the original place.

  • So if I navigate Thio the desktop, for instance, this and then I type in.

  • And if a note folder Dr T accept what I will do, then it will create this note in a specific sub folder and then we'll navigate back into the desktop so I don't get out of the directory.

  • Where where was that?

  • Which is what did it before before navigated into this directory.

  • So what I'm thinking I'm gonna do is I'm gonna have This s the directory or the folder where I keep all the notes.

  • I've created a sub folder within the project that I mean now called notes.

  • And this is where we'll have all the different sub folders for all the different notes that we're gonna take.

  • All right, So the thing that we're going to do now, it's going to be thio.

  • Make sure that you can add pretty much any text file by just typing it out, and then that should automatically create the right type of extension to want to create a dictionary.

  • All right, so these are the extensions that I typically use.

  • There's other ones that we can add in the future.

  • But right now I'm just gonna make do with these ones, and then what?

  • We're gonna do is we're creating a dictionary called extensions and what we can do then this weekend, type in different things that we think people might type in.

  • And then we can map that to Python.

  • So we're just gonna take that in for all the different variations of what you might type in to get these types of files.

  • All right, so what we're doing now is we're checking what the extension is that we've typed in, though, that the persons typed in there were first of all, getting that argument.

  • So this suit's Stark's RG three takes the third argument.

  • This is the syrah with argument.

  • This is the first argument.

  • This is the second argument, and this is the third argument.

  • So we're essentially taking this argument and checking whether that extension exists or maps to one of these extensions.

  • And if it does, then the extension will be turned into that.

  • So if we typed in something that doesn't exist in our map here, then what it will do is it will default to adopt text file.

  • The next thing that we need to do is we need to create the folder, and when we create the folder.

  • We also need to check whether that folder already exists.

  • And if it does exist, then we don't need to create a All right.

  • So now I've created a couple if l statements essentially to check whether the file already exists or whether the folder already exists to get the file name, and we at upended the extension to that file name.

  • So the first thing that we check is whether the folder already exists or whether my folder, my new folder, already exists.

  • And if it does exist, then we changed the directory.

  • So we navigate into that folder.

  • And if it doesn't exist, when we create that folder and then we navigate into it and after we've done this, then we check whether the file already exists within that folder.

  • And if the file does exist, then we'll just open that up.

  • And if the file doesn't exist, then we'll create a new file with that file name.

  • And then lastly, we open the file up with sublime text name of the note name of the folder, name of the extension.

  • And with that, doesn't this open up this thing here, which has new note text which is the file that we created.

  • And it also creates the new folder here, my new folder, and then within that, create that text file that we wanted.

  • Okay, so the next step now, I think it's gonna be to create some sort of search algorithm that's going to go through all of the folders and check whether a file already exists.

  • This might be a bit of a difficult algorithm to figure out, because imagine that you have several different sub folders.

  • It's gonna get pretty tricky.

  • Yeah, we need to We need to come up with a good, good way to solve that.

  • All right, so now I think I've solved it.

  • It's taken me a long time to find a way to essentially loop through the directories and try to find the different files.

  • I was using a different method at first that I thought was gonna work, which was just a four loop and going through.

  • I always start list, dear, which is kind of what you can do normally if you're looking for a file.

  • So I found this other method here called always dot walk, and then you basically just add the path that you want to look through and they call a sub dear and gears and files, and it loops through all the files that it confined within that folder.

  • So even if there are several sub folders, it's still loops through all the files within this folder.

  • OK, so let's run this and see if it actually works, right?

  • So it doesn't work right now, we're going to try to see if we can find a different way to do it.

  • Okay, so that's how it actually works the way it should.

  • So the way that I was able to solve it was by looping through the directories here and basically checking whether the directory is same as the folder name that we provide.

  • And if it is, then we get the path to the sub directory, which we are in, and we upend the folder name to that as well.

  • If the file exists, then we'll return the path to the file where it is.

  • But if the file does six does not exist, then we'll create the path to that file.

  • And here we also set this, uh, the global path to be the path to that new newly created text file.

  • And then we get that back here and we open up a sublime text.

  • Okay, so I think we're pretty much done with this now.

  • I'm gonna go through all the different commands and test them and kind of show you what they dio so.

  • And if he is the 1st 1 that we did.

  • So we create a note folder and the extension, and then we create the folder and then the extension, Dr Dixie, And that will then creates a folder called Hello that you can see here.

  • And it will create my note that takes a nano Open up the note in sublime text and what you can do as well as you can type in an F A A.

  • And then you can just type in and you don't have to type in anything else.

  • It will still create the note, but in that case, it will create it in the general folder.

  • So we'll add it here, all right.

  • And the next one that we created is Theo n.

  • So that's open note.

  • And if you type this in, then you type in the note, and here you only have to type in six characters, and we'll still find the right for the right file.

  • And then you can also specify the sub folder in case the note doesn't exist and you wanted to get put in a specific folder.

  • Then it'll create that file in that folder for you.

  • Some my note that t X t opens up and then you can see it gets created and put into the sub folder that we specified.

  • And then we type in any and then dark file darks.

  • Then it opens up a dark file for us, and it puts that in the right directory, which is general.

  • And it just puts that there because this is essentially, if you don't want to specify where to put it, you just type in any and then that works.

  • There isn't that I wanted.

  • This is because I usually spend a lot of time in the terminal.

  • So it's really simple now for me to just type in Uh oh n and then the note that I want to create.

  • And then I get that note and then I can just type start typing in things so because that's something that I use a lot.

  • I just type in notes and phrases.

  • If I use ever note, then I can't.

  • I have to go into every note, open up in your notes and do that sort of stuff, which I don't really want to do.

  • So this is a really neat way to kind of solve that problem for me, essentially creating my own and note taking app.

  • So, uh, that was the idea, at least for this video, and I'll leave a link to the guitar propose story in the description so that you can check it out if you want, but yeah, that's Ah, it I'm pretty happy.

  • Okay, so that's another one day bill done and dusted.

  • And I'm actually recording this a couple days later, and I've actually been using the script now for a couple days and been really enjoying it.

  • I've used it a lot and wait more than I thought I would, So I can definitely recommend trying this out either trying trying to build it from scratch on your old or downloading the guitar perforce a story that'll link in the description of this video and just trying this out because I really enjoy it and Also before you go, I just want to mention that I've started a newsletter called Clean Code Friday, and that's basically gonna be that.

  • I'll send out one short email every week containing a few of the things that are found throughout this week.

  • This can be things like articles I've read books, some reading podcasts of listen to productivity tips, coding, tips and tricks and really anything that I think you might enjoy.

  • So if this sounds interesting to you, then you can go to caltech dot com slash clean code and you can sign up for it there and then you'll get the next one.

  • And I'll also leave a link to that in the description of this video so that you can check it out.

  • But that's it for this one.

all right, so it's time for a one day build again.

字幕と単語

ワンタップで英和辞典検索 単語をクリックすると、意味が表示されます

B1 中級

一日ビルド。Pythonでノートを自動化する (One Day Builds: Automating My Notes With Python)

  • 1 0
    林宜悉 に公開 2021 年 01 月 14 日
動画の中の単語