TWIL 2021-3 (2)

jh22j9·2021년 4월 17일
0

1. iCalendar url로 JSON 데이터 가져오기


구글 캘린더가 제공하는 iCalendar 파일을 JSON데이터로 변환하여 연도별 공휴일 정보를 객체로 리턴하는 람다 함수 작성하기

ics-to-json 패키지 사용
🔗 https://www.npmjs.com/package/ics-to-json

npm i ics-to-json
npm i node-fetch
// index.js
const icsToJson = require('ics-to-json');
const fetch = require('node-fetch');

const convert = async (fileLocation) => {
  const icsRes = await fetch(fileLocation);
  const icsData = await icsRes.text();

  const data = icsToJson.default(icsData);
  return data;
};

exports.handler = async (event, context) => {
  const url = 'https://calendar.google.com/calendar/ical/ko.south_korea%23holiday%40group.v.calendar.google.com/public/basic.ics';
  const holidays = await convert(url);
  // console.log('holidays', JSON.stringify(holidays));
  
    holidays.forEach((each) => {
    const date = each.startDate;
    const year = date.slice(0, 4);
    const month = date.slice(4, 6);
    const day = date.slice(6, 8);
    const { summary } = each;

    if (!obj.Holidays[year]) {
      obj.Holidays[year] = {};
    }

    if (!obj.Holidays[year][month]) {
      obj.Holidays[year][month] = {};
    }

    if (!obj.Holidays[year][month][day]) {
      obj.Holidays[year][month][day] = summary;
    }
  });
  
  return obj;
};
// output
obj {
  Holidays: {
    2020: {
      01: {
        01: '신정',
        24: '설날 연휴',
        25: '설날',
        27: '설날 연휴',
      },
      03: {
        01: '삼일절'
      },
      ...
    },
    2021: {...},
    2022: {...},
  },
};

🔗 ical-parser는 url이 아닌 .ics 파일로 데이터를 읽어오는 경우에 사용할 수 있다.

2. Terminal, Shell, Bash, Zsh...


  • The terminal is the GUI window that you see on the screen. It takes commands and shows output.

  • The shell is the software that interprets and executes the various commands that we type in the terminal.

  • Bash is a particular shell. It stands for Bourne Again Shell. Some other examples of shell are sh(bourne shell), csh(c shell), tcsh(turbo c shell) etc.

  • Z shell(zsh) is basically an extended version of Bash, with many additional features.

❓GUI는 CLI와 반대되는 개념
마우스로 아이콘 등을 클릭하는 방식의 인터페이스 ↔ 키보드로 명령어를 입력하는 방식의 인터페이스

🔗 Terminal, Shell and Bash
🔗 리눅스 쉘(shell)의 이해
🔗 Deck Out Your Mac Terminal: Z Shell (zsh) Made Easy

3. 데이터를 찾을 때 length 프로퍼티 사용 피하기


matchedItemslineItemID 프로퍼티 값이 2, 2-1, 2-2인 아이템이 들어오면, 2-2인 아이템을 matchedItem 변수에 담아야 한다고 가정

lineItemID 오름차순으로 정렬된 후에 해당 컴포넌트에 들어오는 데이터이므로 .length로 마지막 아이템을 선택해도 될 것 같지만 이는 좋지 않은 접근법이다. 추후에 정렬 기준이 바뀌거나 잘못된 데이터가 들어올 경우를 고려하여 reduce로 가장 큰 값을 찾는 것이 유지보수에 더 유리하다.

//bad
  const [barcodeProductID, barcodeIStockID] = barcode
    .trim()
    .split(BARCODE_SEPERATOR);
  const matchedItems = selectedTask.items.filter(
    item => item.productID === barcodeProductID
  );
  const matchedItem = matchedItems[matchedItems.length - 1];
// good
  const matchedItem = selectedTask.items
    .filter(item => item.productID === barcodeProductID)
    .reduce((acc, each) => {
      if (acc.lineItemID > each.lineItemID) {
        return acc;
      }
      return each;
    });

4. Terminal Keyboard shortcut


command + K : clear the terminal

5. AWS SAM CLI로 로컬에서 Lambda 작업 후 배포하기


🔗 Getting started with the AWS SAM CLI
🔗 AWS 람다(lambda) 실습 Archives

6. Semantic Versioning


v2.0.0 

MAJOR version when you make incompatible API changes,
MINOR version when you add functionality in a backwards compatible manner, and
PATCH version when you make backwards compatible bug fixes.

🔗 Semantic Versioning 2.0.0

0개의 댓글