I have no idea what I'm doing, but here Goes #3 IT WORKS!!

jamonjamon

Jaimie Carter

Posted on June 27, 2019

I have no idea what I'm doing, but here Goes #3 IT WORKS!!

Phew! It actually works. Well, very roughly.

If you've not been following along: 1. Shame on you. 2. To learn Node, I've decided to build an API that automatically chases freelance work for me.

So where were we? trying to get anything out of Google Calendar and make a JSON. That was done, the only problem was - the way it iterated changed the data enough to be a pain when that same data needed to be interpreted. So the challenge was to leave to data extracted by the Google API unchanged, and change it when it needed to be processed, without destroying the original object/s. That way, any part of it can be used in any way, as required. Don't know if that's the right approach, but if felt good to me. And that's all that's important, right?

The github repo has the files.

The major nightmare I had was understanding the function below. I thought it returned and array... but it wasn't was it? It was iterating (wasn't it?) through every event and pushing them/console.logging them one at a time. I think? Don't mistake my confusion for confusion. Sheer terror is a better description. Anyways, I figured that if I pushed them into an array, that might be an idea, and it seemed to work. I'll take that.

    if (events.length) {      
      events.map((event, i) => {
        const start = event.start.dateTime || event.start.date;
        cleanDate = start.slice(5, 10);
        //calData(start);
        array.push(cleanDate);
        //console.log(`${start} - ${event.summary}`);
        //calData(cleanDate);
      });

From there I just needed to manipulate the data, to group days with months and then write an if statement to send string/s when conditions were met. And hey presto! A robot!

I showed it to one of my broadcast friends, and he LOST HIS MIND. "NO WAY! It can do that??"

Yes, Simon. Yes. It. Can. Simon now thinks I'm a genius. I'll take that. It's all about the bullshit factor, isn't it?

Closing shout out:
On the last post I got some great advice from Neil Green. Many thanks for the tips, they were greatly appreciated. The debugger in VScode has blown my mind. Woah!!! How good is a bit of degugging??!!!

Next up: Join this to gmail, and send an email. Oooooooooo. Fun times ahead.

For those that haven't been playing along:
Episode 0
Episode 1
Episode 2

💖 💪 🙅 🚩
jamonjamon
Jaimie Carter

Posted on June 27, 2019

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related