오픈소스

“위키피디아 정보를 ‘명령어’로 한 번에 가져온다” 오픈소스 도구 ‘위킷’

Sandra Henry-Stocker | Network World 2022.10.18
위키피디아 정보를 확인하기 위해서는 언제나 브라우저를 열고 검색어를 입력하는 과정이 필요하다. 하지만 리눅스 사용자라면 보다 간편하게 위키피디아 정보를 가져올 수 있다. 가상 단말기 프로그램 푸티(PuTTY)나 커맨드라인 도구를 이용해 위킷(wikit)라는 명령어만 입력하면 된다. 
 
ⓒ Getty Images Bank 

위킷은 위키피디아 데이터를 커맨드 라인으로 가져오는 도구다. 특정 주제를 요약한 내용도 쉽게 받을 수 있다. 이런 도구로 사용자는 브라우저를 굳이 열지 않고도 필요한 정보를 빨리 가져는 동시에 검색 결과를 파일로 저장할 수 있다.   
 

위킷 이용하는 법

역설적으로 위킷에 대한 정보는 위키피디아에 등록되지 않았다. 아래 내용으로 위킷의 사용 방법을 자세히 알 수 있을 것이다. 먼저 ‘라흐웨이(Rahway)’라는 도시 정보를 위킷을 이용해 찾으면 다음과 같은 결과가 나온다. 

$ wikit Rahway
Rahway is a city in southern Union County, New Jersey, United States. A bedroom
 community of New York City, it is centrally located in the Rahway Valley region,
 in the New York metropolitan area. The city is 21.6 miles southwest of Manhattan
 and 5 miles west of Staten Island. Built on the navigable Rahway River, it was
 an industrial and artisanal craft city for much of its history. The city has
 increasingly reinvented itself in recent years as a diverse regional hub for
 the arts. As of the 2010 United States Census, the city's population was 27,346,
 reflecting an increase of 846 (+3.2%) from the 26,500 counted in the 2000 Census,
 which had in turn increased by 1,175 (+4.6%) from the 25,325 counted in the
 1990 Census.


반환된 텍스트는 다음 명령어로 파일로 내려받을 수 있다.

$ wikit Rahway > Rahway


여러 페이지와 연관된 키워드의 경우, 방향키를 위 혹은 아래로 내려서 어떤 페이지가 있는지 확인할 수 있다. 예를 들어 911 단어를 입력하면, 다음과 같은 리스트가 나온다. 

$ wikit 911
? Ambiguous results, "911" may refer to: (Use arrow keys)
▯ AD 911
  911 BC
  September 11
  September 11 attacks
  11 de Septiembre
  November 9
  911 (number)
  9-1-1
  9-1-1 (Philippines)
  9/11: The Twin Towers
  9/11 (2002 film)
  9/11 (2017 film)
  Reno 911!: Miami
  Reno 911!
  9-11 (Noam Chomsky)

 

위킷 설치하는 법

리눅스 기본 운영체제에는 위킷이 들어가 있지 않기에, 다음 단계를 거쳐 위킷을 별도로 설치해야 한다. 일단 노드JS와 NPM을 설치해놓자. 아래 명령어 중 하나를 입력하면 노드JS나 NPM을 설치할 수 있다. 

$ sudo dnf install nodejs npm
$ sudo apt install nodejs npm


그다음 NPM 명령어를 다음과 같이 입력해 위킷을 설치한다. 

$ sudo npm install wikit -g


NPM 최신 버전을 설치하라는 메시지가 나오면 다음과 같은 명령어를 입력하면 된다. 

 $ sudo npm install -g npm@8.19.2

 

위키피디아 텍스트 가져오는 법

위키피디아 검색 결과에 방대한 내용이 포함될 경우, 앞쪽 내용을 한 줄로 가져올 수 있다. 예를 들어 ‘천문학(astronomy)’ 정보를 위키피디아에서 가져오려면 2,000자가 넘는 콘텐츠가 나온다. 

$ wikit astronomy > Astro
$ wc -l Astro
1 Astro


해당 콘텐츠 내용을 80자로 나눠서 보고 싶다면 다음과 같은 명령어를 입력하면 된다. 즉 -w80은 한 줄당 최대 글자 수가 80자라는 뜻이다. -s는 단어 기준으로 문장이 나누도록 공백 앞에서 문장을 분리하는 명령어다. 

$ fold -s -w80 Astro > Astro2
$ wc -l Astro2
24 Astro2


원래는 한 줄 길이로 인식되지만 80자로 끊어 분리해서 24줄이 됐다는 걸 알 수 있다. 

$ wc -l Astro
1 Astro
$ wc -l Astro2
24 Astro2


여러 단어를 합친 형태로 검색하고 싶을 때 별도로 따옴표를 입력할 필요 없다. 다음은 ‘피칸 파이(pecan pie)’라는 단어를 검색한 예다. 

$ wikit pecan pie
 Pecan pie is a pie of pecan nuts mixed with a filling of eggs, butter, and sugar
 (typically corn syrup). Variations may include white or brown sugar, cane syrup,
 sugar syrup, molasses, maple syrup, or honey. It is popularly served at holiday
 meals in the United States and is considered a specialty of Southern U.S. origin.
 Most pecan pie recipes include salt and vanilla as flavorings. Chocolate and
 bourbon whiskey are other popular additions to the recipe. Pecan pie is often
 served with whipped cream, vanilla ice cream, or hard sauce.


위키피디아에 없는 정보를 입력한다면 다음과 같이 결과를 찾을 수 없다는 메시지가 나온다. 

$ wikit pecan pie recipe
pecan pie recipe not found :^(


위킷에서 사용할 수 있는 언어는 wikit.json 파일에 지정돼있다. 다른언어로 제공되는 위키피디아 콘텐츠를 보고 싶다면 json 파일을 수정하자. 

$ cat .config/configstore/wikit.json
{
        "lang": "en"
}$


위 코드에서 en을 fr로 바꾸면 다음과 같이 '라흐웨이(Rahway)'를 검색어를 영어로 입력해도 프랑스어 콘텐츠가 나온다.

$ wikit Rahway
 La ville de Rahway (en anglais ) est située dans le comté d’Union, dans l’État
 du New Jersey, aux États-Unis. Sa population s’élevait à 27346 habitants lors
 du recensement de 2010, estimée à 30131 habitants en 2017. Rahway fait partie
 du Grand New York.

editor@itworld.co.kr
 
Sponsored

회사명 : 한국IDG | 제호: ITWorld | 주소 : 서울시 중구 세종대로 23, 4층 우)04512
| 등록번호 : 서울 아00743 등록발행일자 : 2009년 01월 19일

발행인 : 박형미 | 편집인 : 박재곤 | 청소년보호책임자 : 한정규
| 사업자 등록번호 : 214-87-22467 Tel : 02-558-6950

Copyright © 2024 International Data Group. All rights reserved.