Placeholder Image

字幕表 動画を再生する

  • all right, so one of the best things about programming is being ableto automate the really boring and repetitive tasks.

  • So that is what today's one day build is going to be about.

  • I've been wanting to find a task that I could automate now for a while, but I haven't had a really good idea on what task I could automate.

  • But then the other day I realized that I used Google Calendar to plan my week, and then I used time to to kind of compare how much time I ended up spending on things versus how much time I use.

  • I planned to spend on things via Google calendar.

  • So what I have to do is I have Thio go through at the end of the week and look at all the different events and tasks that I planned for that week.

  • And then I have to calculate what the total time I plan to spend waas and then compare that to time to where I get the time that I actually spent.

  • So what will be building today is a Python script that should call the Google calendar FBI and then get all of my events for that week, and then it should calculate and some off the total time that I plan to spend on each task for that week.

  • All right, let's start building it.

  • All right.

  • So here's an overview of my current week in the Google calendar.

  • So we want to sell up this this and this and find out like, how much time is spent doing the red tasks and how much time is spent doing the blue tasks gray, green and all that stuff like, Sometimes it might be that it's the same color, but it's a different name.

  • So I think the color is gonna be better because I usually color coordinated.

  • So the first step would be to write out the actual requirements.

  • So what?

  • We want the app to actually do.

  • All right, so this is what I believe are the requirements.

  • So I want to be able to get each event or each task by color, and then some of that time.

  • And then I also want to sum up the total time.

  • So for all the events, how much time do I spend now?

  • We'll have to go into and try to find out how to work with Google Calendar in the eye.

  • So now when I run it, I got this as the response, which is the day here.

  • So the 24 this is what we get.

  • And now I need to figure out where I can see the time, because this I think this is the time when it starts.

  • It's the start times of all the events, which means that I need Thio figure out how to get the end time as well.

  • So that's what I'm gonna do.

  • Now I'm gonna look at what the different calls are.

  • How toe actually get differently.

  • All right, so now I've got the start and end time.

  • So here's the start time and here is the end of time and then the name of the task.

  • So that was just by here.

  • It's a start and then start and start.

  • And I just changed that to end and end.

  • I'm not sure exactly what all the different parts of this dust, but when I changed it to end, it worked.

  • So that's good enough.

  • I'll create something like a class that's got the actual date and then the start time in the end time in the name of the task and maybe the color of the past.

  • All right, so now I get the color of each event.

  • So if a runner, then I get this response, which is the hex color code, then if there's no color, which apparently it is, if it's blue, it throws an exception.

  • And that's why it took me a while to get that toe work, but not work.

  • So I just catch that exception and say that it's like Blue.

  • So then I just need Thio kind of look at all the different colors and figure out what they represents.

  • I'll try to figure all that out, and then I will create a method or something for actually calculating all the stuff that I want to calculate and then printing it out to screen so that I can see like, Okay, this is how much time I spent on this thing in this summer's times.

  • But no the other thing.

  • But I'm pretty happy.

  • It's getting along pretty, pretty good.

  • Now.

  • I think it's time to move over to the couch and turn on some how I met your mother.

  • Kids never underestimate.

  • Yes, you expect the wind was thinking cause a ripple effect that changes.

  • All right, so now what I've been able to do is get how many hours is in each task.

  • So here you can see this is Thea Hour.

  • This is the hour.

  • This is the hour and so forth.

  • And it was quite difficult because apparently when you get back, I got some error like it was the whole date.

  • But when I printed it out, it was It's still said, just 13 and 15 for the hour.

  • It shouldn't have the date, but apparently did so I had to convert that somehow.

  • Thio uninjured your And this is how I did that in this method.

  • And then now what's left to do is categorize.

  • It's because right now if I edit video or something, then I will get several different tasks that are all the same like edit video.

  • So I need to combine those into one test and then summarize it and give the total time for that that collection of that task.

  • So that's what I'm gonna do now.

  • So now whenever meant by get this which is a summary of all the time that I will spend on different things.

  • We get the name of whatever activity or category I have set the activity s and what I did was up here.

  • I created some variables for each color.

  • So this is the tomatoes, so that's red.

  • And that's YouTube.

  • And this is where you can just define that name to be whatever you want.

  • If the color is red and the color is consistent with whatever you're doing, then it should the categorized under the task you tube.

  • And then I did that for all of these ones.

  • So for Flamingo banana tangerine, I don't have any tasks currently, so I don't have names for those.

  • I also created a map that's called color activity, and basically each number represents a color.

  • So zero is lavender and one blueberry.

  • That's just so that I can.

  • Then, by knowing the color, I can get the title of the whatever activity this so that down here.

  • Then I looked through all the colors of the events and then if the color is equal to whatever, then set color idea that task to be zero.

  • So that then when I looked through all the different tasks that I have, Then I could just check if the idea is zero.

  • Then it will get me the lavender task name.

  • So this is what it's like right now.

  • The 1st 1 here is from 14 which is what the time is.

  • Right now.

  • The last thing, basically is just to make it go for from Monday till Sunday or from Sunday till Sunday from some late Saturday, I don't know.

  • So that's the last thing.

  • And then it's I'll just make it maybe a little bit nicer in how it's presented.

  • And then, uh, that's it.

  • All right, all right.

  • I think that we're done, and I'm just going to make this a bit bigger.

  • The way that I did it was that I had to first do this.

  • So I get an end time, which is just the start.

  • The right now dates, and then I add seven days with the method.

  • Then we loop through it, and then we summarize it.

  • So we summarize so much time to spend on each task by the color of the test, and then we print out for whatever task name you have planned to spend this amount of ours.

  • All right, Now let's run it and see what happens.

  • All right?

  • So for of maybe I should actually.

  • All right.

  • I think it's time to go for a little walk.

  • Thank God that held.

  • Okay, Now we're back and let's get back to us.

  • All right?

  • So now I can get your way.

  • Get Yes, he gets everything that we want.

  • We get for exercise you plan to spend, spend 4.5 hours is and for my app.

  • So you plan to spend seven hours a week.

  • So basically, this is what I can then use, and then I can go into this.

  • And I can look at how much time I've worked too.

  • Well, also, this doesn't taste in Monday, but I could Yeah, that's the That's they'll.

  • Okay, that's the last thing I have to add.

  • So that actually starts on Monday because that's when this starts so that I can actually get the really weak, but I I'm gonna have All right.

  • So what I'm doing now?

  • It's I'm just getting the dates of the start day, which is today.

  • And then I'm getting that day again in the Nam subtracting the day of the week that it.

  • ISS zero is Monday.

  • One is to stay.

  • Two is Wednesday, today's Wednesday, and so it would subtract two from whatever the date kiss.

  • And then we should get the current Monday in this case for me, and then it prints all the activities.

  • So this is what it does.

  • It shows us okay for excites you 10 7.5 hours this week, and then we can have a look at a calendar and see whether that is correct.

  • So one that's easiest school, which is great.

  • And that 7 to 9, which is two hours and then 11 to 12 which is one hour.

  • And it says three hours here for school, which is the time that I had planned to spend on it.

  • It seems to be working, and I'm pretty happy because now I can.

  • Like I said, compare this to what's how much time I actually ended up spending on different things.

  • So basically, that's how I compared.

  • I look at how much time I plan to spend, and that's this summary.

  • And then I look at how much time I actually spend, and then I can kind of get an idea off whether I shared plan Maur things or playing less things.

  • But yeah, this is a really good example of a task that can be automated very easily with python.

  • And I'm really happy that I did this because I think I would use it a fair bit.

  • So yep, that's it for this one day build.

all right, so one of the best things about programming is being ableto automate the really boring and repetitive tasks.

字幕と単語

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

A2 初級

一日ビルド。Pythonによるタスク自動化 (One Day Builds: Task Automation With Python)

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