Placeholder Image

字幕列表 影片播放

  • Hello.

  • Good afternoon.

  • Good evening.

  • Good night.

  • Good morning.

  • There are so many time zones all over this world that we live in.

  • I am not part of today with my my commuted, which is rare because often start like muted.

  • And it takes me about five minutes to realise that.

  • And then the 1st 5 minutes of silence.

  • But today I'm actually speaking to you.

  • It's Friday.

  • I am looking forward to this weekend.

  • Um, yeah, there's no doubt about that.

  • But that's not what you're here for.

  • It's been a long week.

  • Retire.

  • There was already a live stream today with guests and feel insane, which I will.

  • You mentioned.

  • I mean, imagining it now, but I'm back to continue the threads of last week earlier this Monday.

  • Let's see.

  • Sorry.

  • Let me get the Shatt chicken going here.

  • All right, so Hi.

  • Who's literally ready yet?

  • So let me open up a Web browser.

  • I'm completely unprepared for this in as I always am.

  • Like, I can't even get my Web browser to open.

  • This is how unprepared I am.

  • So if I live in low later, I don't want to try safari.

  • Thank you.

  • Um, if I go to this YouTube channel called the Coding Train.

  • There's an upcoming live stream and one right now.

  • That's interesting, but this is what I wanted to refer to.

  • So this morning this live stream happened this morning, which was Ah, Lifestream, sponsored by Spell, which is a cloud computing service, and guest Nabeel Hussain trained A L S T M neural network, which is a kind of neural network that's well suited for sequences trained model on a text.

  • So text from an author this, in this case a rapper was used song lyrics were used at the model was trained.

  • And then after that was completed, that model was brought into javascript into the browser and can be interacted with generating new lyrics.

  • If you're interested in that, you can check out the live stream.

  • From this morning, we did have some technical difficulty a few times here and there.

  • So at some point I'll probably be producing an edited version of that.

  • It was actually only was only 58 minutes.

  • My guess is the edited version be like 35 or 40 minutes or something like that on Rui in the chat room, we re gamer who was watching me, my other gentle that I will not mention the secret laptop.

  • It's not so secret, right?

  • Here it is.

  • It's not that I want this laptop to be secret.

  • It's that it's just too many things blocking the way.

  • But, um uh, I was talking about remember I'm so tired.

  • You look so tired.

  • All right, but I'm on a mission here.

  • None of the last on Monday earlier this week Here it is mastered on trying again.

  • I spent two and 1/2 hours creating a master Don Pot talking about what Master Don is, which is an open source decentralized social networking platform.

  • Um, I created my own instance called chu chu dot space.

  • It's still there.

  • Koji member of choo choo dot space has posted this wonderful picture of a koala that Okay, we're totally using this fixture.

  • Uh, you know, how do I get this image Copy?

  • Image address, maybe?

  • Yes.

  • Okay.

  • Thank you, Koji, for somehow knowing that I could use an image of a koala Kuala.

  • Let's put it on the desktop.

  • Uh, okay.

  • I don't know if I really use this, but I'm saving it for later.

  • Um and magic carp over here is talking about Nice to see Shiffman talk about mastodons.

  • OK, thank you.

  • All right, So this is Master Don and the instance that I'm using with my coding train baht is master Don that space bots and space.

  • Sometimes my words keep coming out my mouth But my brain completely shut off my brain completely shut off!

  • And words just kept coming because I'm live streaming and I feel like if I'd stop talking will be silence.

  • But what would be the worst thing about silence?

  • All right, that was good little moments.

  • Silence there.

  • Have you refreshed?

  • How do you feel?

  • I'm trying to decide if this makes sense to be a coding challenge like mastodons.

  • Image, baht processing image bought with things I love about this example that I'm going to do today is it brings so many things together, brings together a P eyes and node and javascript a synchronous I'm gonna use a sink and a weight which is like yes eight job scripts in text and processing and creating images and shell scripting Also many pieces together into one project.

  • The project that I'm going to build is a project that starts with a processing sketch.

  • Let's see, our recent this version of processing I have is, um, 3.4.

  • That's perfect.

  • Starts with the processing sketch from node executes the processing sketch.

  • The process sketch saves an image node, grabs the image, uploads it thio mastodons, media server then posts a toot to master Don referencing the image.

  • So if we look at bots in space one of my favorite let's look at the local timeline.

  • This is nice posting gifts.

  • But I really like the tree.

  • How do I find, um, see if I search for tree, But I think I can actually just go to bots and space if I want a cube storm.

  • Oh, it would be, Ah, cubes.

  • So interesting.

  • The u R l for an account is its number, so I can't simply just know the name of it.

  • But let me tree bought at box in that space.

  • Will this find it for me?

  • Here is the Yes, there we go.

  • No, I don't mail it.

  • Ah, I don't know how this random trees.

  • Oh, no, I can just do this so I can do this tree Buck.

  • Here we go.

  • No, no.

  • Ray Allen is random trees.

  • It's random trees.

  • Random trees.

  • I'm like a lunatic.

  • Uh, how long?

  • Oh, this is a different pot.

  • This is totally a different body.

  • You're the one I was looking for.

  • The fractal tree one.

  • Nobody will tell me.

  • Art.

  • Yes.

  • Mastered on again because it's not master that again.

  • It's so what do you What should this be?

  • A, uh, it doesn't really matter.

  • I'm making the video.

  • I think that I like the idea of trying.

  • This is a coding challenge.

  • Uh, dream body.

  • There's a different tree body.

  • Hold on.

  • How many bots could there be on bots in space?

  • Just just humor me for a minute.

  • Here.

  • I like it.

  • Posts free often the one that I'm thinking of.

  • All right, I'm gonna give up in a second.

  • Who?

  • I like this one Emoji.

  • DNA.

  • That's pretty awesome.

  • Mmm.

  • Emoji.

  • But it's kind of fun.

  • All right.

  • Um, s Oh, here we go.

  • Do I want to create a new But I think I'm gonna use the prince.

  • So I think I'm gonna do this is a coding challenge, but I am going to get myself.

  • Who set up a little bit.

  • So what I need is to close these things.

  • Then I need I term open.

  • Uh, it's It's all the update.

  • Okay.

  • God, I term open.

  • We're going to go to of the desktop mass Adan and open this.

  • We're going to get master done, But Thio, look at all this stuff in here.

  • Master Don bought two and this is going to be tree underscore Bought.

  • Thanks.

  • It's tree underscore bought.

  • Thank you.

  • Tow alcove for finding that for me, Master Done.

  • Bought three bots and space at three.

  • Underscore Bach.

  • Yeah, this was looking for I want to make exactly this.

  • Who created this?

  • Are they going to mind about general trees made by Alex Novi Sony?

  • Um, okay by this person.

  • All right, I'm gonna recreate this.

  • This is gonna be my coding challenge.

  • Um, then I close this.

  • I'm gonna be here.

  • I'm concludes this.

  • I don't need this.

  • And then I need processing, and I need This is gonna be long.

  • I don't I don't I don't care.

  • I'm gonna do this the way that's gonna be right on.

  • Then I need code visual studio code open and, um, close.

  • These, um my son about 30 boy.

  • Oh, boy.

  • I don't need any of these files that are extra stuff.

  • Um, and everything else is fine.

  • Uh, and then I'm gonna start with this much code.

  • I'm gonna start with this much, coach.

  • What I'm trying to decide is should I do this?

  • I mean, this really doesn't matter cause I want to just make this project.

  • Here's what I'm gonna do.

  • I got an idea.

  • I'm going to act as if this is a coding challenge, but I'm not going to say the words coding challenge aboard and just do it as if it's a tutorial.

  • And then at the end, if it feels like it could actually be one video coding challenge, it doesn't end up being multi part tutorial.

  • Then I will record a brief intro calling it a coding challenge.

  • How about that?

  • Everybody wins, and I win.

  • I mean, I don't know.

  • All right, we're gonna check out this white board thing over here.

  • Don't think that I need you know what, though?

  • Uh, Why whoa of wrong.

  • Oh, there it is.

  • Um, do you want to erase the whiteboard?

  • Actually, which I'm going to do very quickly with my fancy racer mechanism.

  • Um, if I could find it, I can't find where it didn't get thrown away.

  • My erasers.

  • I know you can't see me right now.

  • You don't want to be seen.

  • I want to be seen looking for the eraser.

  • Am I going have to go in the hallway and get a paper towel?

  • The earth will be very sad.

  • Have a nice reusable eraser, doo hickey.

  • That was completely Oh, here it is.

  • Found it.

  • This is actually Yeah.

  • Okay.

  • Okay, there we go.

  • Now.

  • I got a marker.

  • I am going Thio.

  • Okay, here we go.

  • Everybody stretch.

  • Stand up, Stretch with me.

  • And really, this is maybe some correct stretching thing.

  • All right, So other things that I need open here are, um I need, um I need the master.

  • Don ap I docks and Master Don a P I docks.

  • Okay, so these I will definitely probably need to reference.

  • I got tree bots.

  • I've got the coating train bots, and I've got some code.

  • Uh, let's just make sure like that.

  • Does something Okay.

  • All right.

  • Ooh, I got a notification.

  • I probably should turn those off.

  • All these people are following me.

  • Look at everybody all of a sudden.

  • So much activity here.

  • Okay.

  • Um um Okay, let's just want to do something here.

  • It's go back.

  • That's good.

  • Um, all right, So I'm trying to figure out, like, if there's just want uh, Can I just get rid of this for a little place sound?

  • Let's get rid of this place soundly sound.

  • I actually can't clear notifications.

  • Yes, I know, but I turned them all off.

  • There's no way to just, like, turn them all off private unp in.

  • Yes, there we go.

  • It just don't want I'm afraid of random stuff appearing that other people are posting.

  • All right?

  • Oh, Adam in the chat.

  • Apologies.

  • So if you want to join church, you got space.

  • I have created invite for, um, members of YouTube channel and, uh, patrons.

  • But I'll have to get off the generator.

  • I didn't realize that it expired.

  • I'll generate a new one after this is over.

  • Okay.

  • Hello.

  • I'm going to make something in this video, and what I'm going to make is a tree.

  • But I love this.

  • Bought it is a bought on mastodons called tree underscore bought it is made by Alex Novo.

  • See was made for Nam nab Oh mama which is must be some like national bought making month natural about making with when does that happen?

  • Is it now We should all make bots for national about making months.

  • So I am going I love this spot.

  • It makes a This is my one start over my poor guests who come here to do a guest video.

  • I don't let them like they don't start over like 15 times like me As if I wasn't doing this life.

  • Hello.

  • In this video I'm going to make a pot and I'm going to make it image.

  • But I'm very excited about this project because it pulls together a whole lot of different things.

  • I am going to use processing generated image.

  • I'm going to use node to ex to call processing to generate the image that you know to talk to the a p i and the a p I.

  • It's mass it on.

  • So one thing you might want to do is I'll refer you to all of my a tutorial.

  • Siri's about the basics of making a massive on, but I will start largely from scratch here.

  • But I am going.

  • I've already got my A p I keys and I already have imported and installed this node package called Masterton dot a p I and this dot envy package that that loads my a p I keys for me.

  • So that is stuff that I've done in another video.

  • If you want to see that a link to that in the video description.

  • But I'm just gonna get started.

  • So what is the first thing that I want to D'oh Okay, let's goto So this is my inspiration Tree bought, made by Alex Duboc for national bought making month.

  • Um and I am going thio try to recreate this.

  • Trees won't be nearly as nice.

  • So the first thing I wanna do is I want to use processing.

  • I don't have to.

  • I could find some note package that does drawing or generates an image spg whatever.

  • But I love processing.

  • It's my happy place.

  • And I'm pretty sure I could get prostitute generated tree.

  • I don't even have to, like, write the code for this because I have before I'm just gonna go Two examples, right?

  • Isn't it in here somewhere.

  • Topics simulate.

  • No, no, no.

  • Okay, I'll be back in a second.

  • I came back.

  • I found it under fractals and L Systems tree.

  • Well, look.

  • Recursive tree by Daniel Sheaf Mon This is my This is a recursive tree, and as I move the mouse, it changes the angle.

  • So let's alter this code a little bit.

  • Let's say that we don't care about a frame rate and let's not let's have the angle be random between zero and two pi.

  • Oh, and it's converting it to radiance.

  • Okay, between zero and 3 60 Oh, it's doing it over and over again and draw.

  • That's exciting.

  • I'm gonna say no loop.

  • So it's done.

  • Each time I run this, I get it random treat.

  • It's so much more than I could do to the design of the tree.

  • And I'm so tempted to recode the tree.

  • But I'm going to just leave it as is.

  • You know, maybe I want to, like, not have so many large angles.

  • And there we go.

  • Beautiful tree.

  • Okay, so now, now that I've done that, what I want I want my processing sketch.

  • You also save, uh, I'm just called tree dot PNG So when it's done drawing, it's gonna save an image.

  • Okay, this is exciting.

  • Now I need to save this somewhere.

  • Where?

  • Where?

  • I got my master Don code right here to talk to the bomb.

  • And so what I want to do, actually is I promise to talk to the baht.

  • I've got my message.

  • Brain has turned off today.

  • What stretch break?

  • Oh, God.

  • I've been having water over here.

  • Going to slow down.

  • Yeah, I made the tree and p five also in a coding challenge.

  • I've got my code here.

  • This is the code that will talk to the mastodons service on what I want is for this code to actually run a processing sketch.

  • But this is knowed This is Java.

  • Script processing is Java, and it's like a desktop environment where I hit the play button.

  • How can I possibly do this?

  • Well, the first thing I'm gonna do is actually go and save this processing sketch in where my body is.

  • And I'm actually working in this folder.

  • Macedonian bought three.

  • You can see no modules bought the Js, so I'm gonna save it there and I call it Tree Tree.

  • Jen, so I'm gonna save it.

  • Tree Jen, I'm gonna make sure it's still runs.

  • It still runs.

  • Um, And now what I'm gonna do, I'm gonna show you a little trick.

  • Now, wouldn't it be nice if in the in terminal I could do things like just say, hey, run processing?

  • But says processing is not found.

  • What if I were to say, processing dash Java permission denied?

  • It's different.

  • How interesting.

  • You know, I was gonna do that.

  • Wouldn't it be nice if I could just execute a command like processing run course in terminal?

  • And the shells are going to know what that is, but a little known fact about processing, which I have done this in other videos before.

  • But just a start anew again processing command line.

  • There is actually a way to run a processing sketch command line by saying processing dash job of the path of the sketch and then dash, dash, run.

  • But the only way you could do that is by installing first processing dot java to your system.

  • So this is installing a command line, um, command to run a processing sketch.

  • So I'm gonna do this.

  • Install process java I'm gonna say yes for all users.

  • Um, it's going to want to use my password, uh, enter my password because it needs It.

  • Needs to be able to put that where it needs to go.

  • And now I can actually say processing dash java and you can see I get all sorts of stuff.

  • It doesn't know what I want to do.

  • But watch this.

  • I can say, Let me just look in here.

  • There is the tree jen processing sketch so I could say processing dash Java sketch equals Is that what itwas Let's go look at the sketch equals now I need the full path.

  • So the full path and I'm gonna show you a way around this in a second.

  • Is this tree Jen right?

  • This is the full pack of that process sketch that I could say Dash, dash, run.

  • Here we go.

  • Magic.

  • It ran it.

  • Look, there's the processing sketch.

  • This is really cool.

  • Now watch what's exciting about this and it's bothered me that the background isn't 51 which is very important, like actually quit processing completely.

  • I don't need that crossing open and still do this.

  • There it is.

  • There's my tree.

  • Beautiful.

  • But I actually do you wanna have processing?

  • Because I got a little bit of a problem here, and we can see here.

  • Look, that image is there.

  • It's now saved.

  • What I want to do is go back and open this again.

  • Open, open, open, open, open.

  • And I want to add one thing like I want it to be.

  • I want it to go away.

  • So I actually want to say after I save it exit.

  • And I'm also this is gonna be helpful for me later.

  • I want to say print line, tree generated.

  • We'll see where this comes up later.

  • Okay, Now, quick processing.

  • And now I'm gonna run this.

  • There is no finished regenerated.

  • Finished.

  • What time Finished.

  • Okay, this is really exciting because there's so much stuff you could do.

  • Now, here's thing.

  • I am executing this command via the shell, but I want no to execute it.

  • How can I execute it in note?

  • And it turns out there is a way to execute any generic shell command from known.

  • And it is with the child process package.

  • So if I go to child process, you'll see here that there is a method called execs child process Stop exact.

  • Spawns a shell and runs a command within that shell.

  • Truth of the matter is, it might be useful to use this execs sink because I'm gonna wanna sink mean synchronous meeting.

  • Wait until it's done to go into the next thing.

  • I've got a crazy plan here.

  • I want to do a synchronous stuff with s eight.

  • This weight in a sink function you may or may not have heard about.

  • So I'm gonna use this one.

  • Exact.

  • So what I need to do is in my note code.

  • I need to say const exact equals require.

  • And where was this?

  • It is in child process dot exact child underscore process.

  • No, there's no.

  • Yeah, that's right.

  • Huh?

  • Oh dot Exact.

  • Yes, I'm confused.

  • So this is me requiring the child process package, and I don't have to npm install this.

  • You'll know you notice that I'm on the node.js documentation page.

  • I'm not in some separate third party and P M package.

  • This is built into node, but just like file system is.

  • But I've got to say that I want to use it so require child process and All I want is that exact function.

  • So now there's no reason why I can't just say exact and then pass in.

  • What exactly?

  • This Let me make This is so unwieldy.

  • So a nice little trick that I could dio is I can actually always get the current path, right?

  • If I want to get the current path, I just type P W d print Working directory.

  • Well, guess what?

  • I could actually have a p w d executed within this command by using these back ticks.

  • I'm pretty sure that Zoe do it so now and say Run.

  • And I think I don't actually even need this.

  • First slash right?

  • Run sketch equals print.

  • Working directory.

  • Ven tree Jen, run.

  • Let's see if this works is done.

  • Okay, so now, um so great.

  • So I can grab this.

  • This is my command.

  • We'll get to that.

  • The master don stuff in second, uh, constant command equals.

  • Let's just put this in a variable like this, then I could say exactly command, and then that's gonna have a call back.

  • I don't want to let me just run this.

  • Let's just run this.

  • Let's see what happens.

  • Note about dodgy es.

  • Hey, look what happened.

  • It made it happen.

  • Now, here's the thing I was The next thing I was gonna do is add a call back, But I'm a new I'm turning over a new leaf.

  • I'm turning a new page in the book of JavaScript and I'm I'm a kind of person who uses promises I'm not only kind of use a person uses promises.

  • I even used the A sink and await key word to really make my life full of just ese.

  • It's not full of these, but I'm doing my best.

  • So what does that mean?

  • The thing is, this particular note package, child process dot exact.

  • And I have a feeling if I bother to look at the chat, we're gonna open up for a second.

  • Someone's gonna tell me I could just use something else.

  • Now that natively supports promises, the E key does not work on this computer, which is invisible to you.

  • Oh, it's the wrong I've been typing in the wrong password.

  • Okay, there it is.

  • Um um Oh, I'm being told that no Dutch s has underscored directory name.

  • So the other ways people tell me other ways you could get the directory name.

  • But what I'm going to do is I'm going to promise if I which is a word, apparently promise if I I'm going to look at this.

  • I must have googled this another time.

  • Listen to this.

  • Very common by using java, not job.

  • Sorry.

  • The node package you till so node package you till if I go look atyou till, um and actually just want to be here.

  • There is a promise if I you til dot promise If I So what I could actually do is I can say, uh, const Util equals require you till and then I can say Ah, you til dot promise If I had a weird word Well, what happens if I promise if I myself this So now this require child processed exact function no longer uses a callback Now uses a promise.

  • And what does that mean?

  • That means I can say God then And whatever the result the responses I can console log that response And then I can also catch any error when I can console dot error that error.

  • Now this might be And this this There's no semicolon there.

  • There's a semicolon there.

  • This might look completely insane to you if you haven't seen promises used before in job script.

  • It's very similar to a call back.

  • But instead of saying a callback basically have this callback that happens in Doctor and I'm also using the aero syntax, the arrow syntax is a nice way of short of short handing.

  • This I'm getting the response is the argument to the call back and I'm console logging it.

  • So if you want to know more about those things, I have a whole playlist about promises Anna and a video about the arrow function that you could go and look at.

  • This is the basic idea.

  • This is a little bit of an advanced video here with not advance, but just I'm using kind of modern drama script stuff you consider, like, three years ago modern.

  • Okay, um, so now I've got this exact function, so let's actually run this one more time and see to do exactly the same thing.

  • But look at this.

  • That response has standard out standard error.

  • So, in other words, standard out is what That's the thing that I closed my process sketch.

  • I guess I should have left it open.

  • The process sketch has a print line in it.

  • So I can read whatever that print line is like, actually get more information from processing.

  • If I want, for example, I could get the angle.

  • Actually, this this is great.

  • Let's add a little feature to this.

  • This will be fun, because why not make this video longer than it already is?

  • Um, where my desktop desktop.

  • A master Don Masterton bought three tree Jen.

  • So what I'm gonna do here, Look at this thing is great.

  • Let's leave this open because maybe I'm gonna want to do more stuff with it.

  • I am going to Let's just make the angle between zero and 90.

  • That's what it says in the comments.

  • And then I'm also gonna say print line and I'm just going to say angle.

  • Or is it was it angle?

  • Fada, Whatever A I'll just keep the A and I'm gonna say floor a Just get the just get the r into aims to convert it to an integer So watch.

  • So now when I do this in In Node, I'm gonna say console dot log response dot standard out So I don't need to see that whole object.

  • I just want to see the stuff that came out of processing.

  • Let's run it one more time.

  • That was the angle.

  • 42 spooky, spooky 42 beating of life.

  • Okay, so great.

  • So here's the thing I want to Once I have that image, I want to post that image to methadone.

  • Isn't this all about Master Don?

  • I've loaded up connected to Master Don through this like pot.

  • If you don't know what mastered on is that I say this already.

  • I've got a whole set of videos describing that.

  • I mean, you could go back and look, but I want to somehow post it to this particular bought the coding train.

  • But okay, so now, in order to do that, I need to I need to look up the functions in the master on a p I.

  • So I'm using this mastered on a p I knowed package.

  • And if I go here, I can look and see that it has mastered on get Master Don post.

  • So this is what I want Mass on post.

  • Here's the thing.

  • I didn't realize this when I made my other videos about master Don because it says path parameters and call back.

  • But guess what?

  • This supports promises.

  • So I actually going to do this without a call back with promises.

  • I'm going to break this out.

  • Didn't they say I was going to use a sinking await was gonna write it with just that, But I think I have to start a little bit.

  • I have a little bit further with the full promises, syntax that I'm gonna clean it up with a second.

  • Wait a second.

  • So now there's no semicolon there.

  • So now what I want to do is I want to basically say this.

  • I want to post the image, and I want to return this because if this returns a promise, guess what I get to do.

  • I get to say dot then response and have another function.

  • Right?

  • So this is the idea of chaining promises and this is what, in theory, I mean, basically, the whole theory of this is to avoid callback.

  • Hell and really, we just did promises.

  • Well, it's all hell.

  • But eventually we will float into the clouds, and I feel like we're like butterflies on wings or something.

  • I don't know.

  • Okay, so if I return the post that I want to do when that's done So I'm excusing this command when that's done, then do this vet and then when the next promises done, then do this.

  • So what do I need?

  • Your The path?

  • So the first thing I need, what's weird about and actually it might be worth just taking a minute to, like, right the steps out, it'll make it more clear.

  • I want to exact processing.

  • That's one Then, too, I want to upload image and then three I want to toot.

  • All right, So what?

  • This is the same thing for to the twitter a p I It doesn't work that you just if you want a tweet an image, you don't just simply send your tweet along with the image, you have to first upload the media, get that path to the media, and then you can tweet with that media reference.

  • So this will actually return, and i d for the media.

  • And then as long as I attached the i d to this.

  • So this creates output, Doc.

  • PNG.

  • This creates an I d and then use that i d here and then I'm done.

  • Then we're just, like, done.

  • This is the three step process, each one of these returns of promise.

  • So when do this, then this, then that.

  • All right.

  • That's the process I'm working with here.

  • All right, So, um, now, um So Okay, so the path So let's go to the mast.

  • It on a p I docks.

  • And I'm actually looking for a media.

  • We can click here, and this is what?

  • I don't know.

  • I don't media upload.

  • I think media uploads just this I post to hear.

  • And then these are the things I need to send.

  • Okay, so file description focus.

  • Let's look at that.

  • Okay, So I need thio.

  • I'm gonna create some parameters.

  • Oh, no, I'm up here.

  • I'm just gonna I'm gonna create some parameters and I need the file, which is presumably output dot PNG.

  • And this is not exactly right yet.

  • I can't just put the file name there, but I'll get to that in a second.

  • Then I want the description of the description is really important.

  • This is not the text that is going along with the actual post.

  • What?

  • This is all text alternative text.

  • This is for accessibility.

  • So somebody who is blinded with low vision was using a screen reader instead of seeing this image would actually hear this description.

  • So I would say, a randomly generated fractal tree.

  • Oh, and I want to get This is I'm gonna say const angle equals response dot Standard out uh uh, with, um and then when I need to use my new thing that I always use now, which is, uh, template liberals for strings with angle.

  • So this would be the description.

  • And then there's one other s o.

  • The file is required.

  • The description it says is optional, but it really shouldn't be optional.

  • You should be using all tax for accessibility and then focus.

  • This really is optional.

  • I am assuming actually not tried this yet, but I'm assuming this has to do with where the crop is.

  • If it's showing a preview image, something like that.

  • Okay, so then I can say so.

  • This is done on then path and then those parameters because this could be an array Oh, path.

  • No, but okay.

  • Path.

  • Oh, yeah.

  • The path is media.

  • Sorry.

  • I'm posting to this path.

  • The media path off the A p I with these premise, but this isn't right.

  • I mean, let's run.

  • This will get an error.

  • So I make the image finished.

  • Paramus is not defined.

  • That's a different in her Paramus programs.

  • Whatever.

  • One more time.

  • Run the baht.

  • Weirdly, it's like, didn't complain at me.

  • Uh oh.

  • But, oh, why didn't complain?

  • Because I didn't console log this response.

  • You know why I'm going crazy to show you this era when I could just fix the error in the first place.

  • All right, so all this stuff came in, and it looks like maybe this worked because I'm getting all this stuff.

  • But somewhere up here, I'm gonna see, like, an error code.

  • All so much stuff.

  • False high water, Mark.

  • I don't know.

  • This seem to have worked.

  • No, this is nonsense.

  • This is saying this page is not correct.

  • Let me go back.

  • But this doesn't.

  • This doesn't need I gotta edit this out because it's not that.

  • Just go back to here, So this is almost done.

  • But there's a problem.

  • I can't just pass it.

  • The file name.

  • This actually needs to be a readable stream.

  • And so I need to use the files file system package if I go and look for node file system package, Um, in here somewhere, I think there's, like, a create stream function.

  • Actually, Probably a better place for me to look is just right here in.

  • Um, hold on.

  • Well, I don't have to do this again.

  • People are some stuff going on.

  • Oh, soup.

  • Ernesto, I didn't I didn't look into that.

  • No.

  • Sorry.

  • Um uh, sorry.

  • I forgot.

  • What it iss create Read stream?

  • Yeah, that's what I want, I think.

  • Okay, I'm pretty sure that's what I want.

  • Sorry.

  • Let me go back and do this one more time.

  • Thank you, Mathieu.

  • All right, Um, almost there.

  • But this actually isn't correct.

  • It doesn't work, Theeighty eyes not going to just accept a string of the file name and figure out howto read that file and post all the date of that file to the server.

  • What I actually do is give it a readable stream.

  • And if I and so the code for doing that, it's part of the file system package.

  • So I need Thio.

  • I need to actually also require that we could look up the documentation for it, but I happen to know it.

  • I think so.

  • I need to say I'm just a constant stream Ingalls file system create.

  • There it is.

  • Read stream auto complete.

  • Thank you.

  • Output.

  • PNG.

  • Oh, and this actually isn't even right, because guess what.

  • Remember, output that P and G was saved in the process sketch, which is the folder tree jen slash output PNG.

  • So now this is the stream, and this is the description that goes with it.

  • Okay?

  • And then I want to make sure this worked, so I want to actually console log the response.

  • So now, in theory, I have the code all the way for executing, processing, uploading the image.

  • I need to want to get the response I need to get the i d.

  • And then I go and actually just post the status.

  • Okay, here we go.

  • Let's try this.

  • Unhand, Aled Stream error in pipe.

  • No such foul.

  • That's no such foul.

  • No such file.

  • Oh, it's not called output that PNG call the tree dot PNG.

  • Okay, let's try that again.

  • Finished and great.

  • So look, this is all the stuff that I got back now.

  • It's kind of too much stuff for me to like.

  • Look through what a pain.

  • Did this actually work?

  • My goodness, crazies.

  • But this is all I care about.

  • There's more important stuff.

  • There's more stuff.

  • Lots of tons of meta data about the image you just uploaded.

  • All I really need is data dot i d So let me just go here and say console log response dot data dot i d and I've apologized.

  • Apologies to the bots and dot space for overloading your server.

  • You can see there's the idea.

  • Okay, now guess what can I should I start using?

  • I mean, I just keep going.

  • Why not go with this promise chain things is how I would do it.

  • Probably then Oh, no.

  • And then all I need to do is return One more promise.

  • So I'm also gonna say constant parameters.

  • Now I want to do I need to look at the a p I for, um for what?

  • Post, but just statuses.

  • Um, So this is where, as I'm looking looking, looking, looking, looking, Um, actually, I need to look for a p i V one status is sorry.

  • Oh, I failed.

  • Do it.

  • Maybe I want to.

  • Maybe I should, like, actually now rewrite this.

  • Using a thing.

  • Gonna wait.

  • I'm gonna do that.

  • I'm gonna do that.

  • I'm gonna do that.

  • I'm gonna do that.

  • I'm gonna go from where I printed this out.

  • Now the next step would be for to use this I d And then actually, in the in the in this response, right?

  • I exact execute the command.

  • I upload the image.

  • And then I should be saying return m dot post again and I'm going to status is I should say return m dot post again, and I'm going thio the path I'm going to His status is so this is what I should be doing, but I can't resist.

  • Do you see how this is?

  • I mean, it's great.

  • It's kind of nice.

  • Start the promise chain.

  • Then do this return a new promise.

  • Then do this return a new promise.

  • And if any ever happens anywhere here, catch.

  • So why not?

  • But this is the thing this is now.

  • There is a way.

  • There is a new way for me to write all of this in what feels Maur sequential more synchronous, in fact, with less kind of indentation and brackets and stuff and that is using this a sink and awaits in tech.

  • So what I'm actually going to do is I'm going to write a function.

  • I'm going to call it a tutor or just two, and I'm going to modify this function with the keyword a sink.

  • This means this is an asynchronous function.

  • This is indicating to job script.

  • This is a feature of E s eight new feature of job script That's indicating that this function will be handled a synchronously and always always, always return a promise, and it will auto magically.

  • It will basically automatically return that problem.

  • So we'll look at that leader.

  • How does that so in other words, But this I want to do the same thing, Like what I want to do here is I want to say exact, execute the command, right.

  • These are the steps.

  • And then I want to say post the media, post the media.

  • The nice thing about using the syntax is I don't have to separate it out with these chaining these dot vents.

  • I can actually just use the await key word.

  • What the away key word means is don't go to the next line of code await the end of this function.

  • So if I have a bunch of asynchronous things, if I package them all together in an asynchronous function, I can write them sequentially as line after line after line and essentially, um and, you know, I'm gonna have some other prams here, So this is basically I get to write it like this.

  • Now, I need to do stuff in between.

  • That's the thing.

  • Like, for example, this returns a response, and then what I want to do is get the angle and create the stream.

  • So this goes here.

  • So this is my step one hope.

  • Um, this is my step one, right?

  • Execute processing.

  • Look it.

  • It's just exactly like this.

  • Now I have my step two where I need to create these parameters that are getting passed in, and by the way, I don't have to make a separate variable.

  • Could be embedded right in here, but it's just sort of like a little bit for ledge ability.

  • I'm making it something separate.

  • And so I'm now gonna say, basically, uh, step two is upload, upload, upload media, and that's gonna have a response.

  • And then what I need I need to get the i d out of that.

  • And then I am now going to say Step three.

  • And by the way, I suppose if I'm being accurate about this, this is all I suppose this is part of step two.

  • I don't know.

  • It doesn't.

  • Look, this is a little bit silly what I'm getting myself worked up about.

  • But which line of code is part of which step?

  • I don't know, but But step three.

  • And maybe I'll name this prams one just to be just for I don't know why.

  • Why not Have them have different variable names than step three, which is prams too.

  • I want the status to be on.

  • This is you know, I have to.

  • I think I know it's supposed to be.

  • But behold, my beautiful tree with angle, and then I should use the string litter, the template, liberals again degrees, and then I need up.

  • So now.

  • So this room.

  • Okay, let me look this up in the in the mass.

  • It on a p I docks.

  • Give me a second to find this.

  • Let's edit out me looking for it.

  • uh, a P I G one.

  • The one status is status is he's he's It's gonna be a better way to search on this.

  • Oh, it was all the way at the end.

  • I heard this.

  • Okay, I found it.

  • This is the a p.

  • A.

  • This is the path status is for posting a status, and this is the text of the status there.

  • Other things you could do here that I've talked about in previous videos, but this is what I want.

  • Media ideas.

  • No notice.

  • This is an array.

  • It's an array of media ideas because a particular status could have, and it says here maximum for more than one image associated with it.

  • So you can upload more than one image.

  • So that might be an exercise that you try to do after this video.

  • But basically, now I can say, uh, comma media underscore I d s and I just have that one I d.

  • So I just put it make I can make in a rain, put it there, and then this has to be statuses, Paramus.

  • And then what I can do is I can, and this is the response, And I could just now say return response.

  • So if we could look at this all together, I have to make this like a tiny bit smaller for you to see it.

  • Can I fit it all in one nice place.

  • Look at this.

  • Look how beautiful this is.

  • It's almost like I've written this code in a language like Java or see, that's like, perfectly synchronised and linear and procedural because I'm saying is await executing this command.

  • Then do some stuff, then await uploading the media, do some other stuff than await posting the actual status.

  • And when you're done, return and guess what If I now say we make this bigger again, what's if I say too?

  • Guess what?

  • This to function that I've written a sick.

  • Remember?

  • I said it natively returns a promise.

  • Well, by the way, I said, return right down here.

  • So this thing right there is of the promise it's returning, and I actually might.

  • I could configure my own object, which could be kind of interesting.

  • Like what if I said return?

  • I could just say something like success.

  • True and status, um, stat status.

  • Behold my beautiful tree, whatever.

  • And I could just say angle, whatever.

  • I could put like angle and then that angle there so I could actually configure an object that I could pull stuff out of the response there.

  • I could return that.

  • And then I would say, Then, um then response.

  • I can't spell today.

  • I mean, I could never spell console dot log that response, Catch any error console dot error error.

  • And this needs a period here.

  • And I did save and something's wrong Too many, Not enough.

  • Too many dots to dot Then response.

  • Why come?

  • I can't see this that Oh, there's too many dots.

  • Too many dots.

  • Votes are too many dots.

  • Still too many dots to then.

  • Oh, my God, What's happening to me?

  • Toot then response.

  • Consul Log response Is it just not auto formatting?

  • It nodes.

  • Oughta fortitude then response.

  • Counsel Law response dot Catch.

  • Oh, may I need a semi colon? 00:52:3

Hello.

字幕與單字

單字即點即查 點擊單字可以查詢單字解釋

B1 中級

直播#155。Mastodon影像機器人與處理 (Live Stream #155: Mastodon Image Bot with Processing)

  • 4 0
    林宜悉 發佈於 2021 年 01 月 14 日
影片單字