메뉴 건너뛰기

imp

[GS] ArrayFormula 함수 활용하기

lispro062017.04.07 08:38조회 수 2259댓글 0

    • 글자 크기

ArrayFormula 는 영역의 내용을 그대로 참조할 수 있다.


importrange 함수는 다른 파일(스프레드시트)의 영역을 참조하는데, limit 가 걸려있고, 느리므로 별로 안 좋아한다.


ArrayFormula 를 이용해 다른 view 를 구성하는 것이 필요한 경우 사용 가능하다.


A, B, C 컬럼 중 A, C 만 연속해서 활용해야할 때 좋다.


더더욱 좋은 것은 문자열의 가공이 가능하다는 것이다.


=ArrayFormula(if('sheet'!V3:X="",,left('sheet'!V3:X,19)))


V3 행부터 X 행 전체 내용을 가져오는데, 비어있지 않다면(내용이 있다면) LEFT 함수를 거쳐 출력하는 것이다.


원래 내용은 20자인데, 별로 안 예쁘게 출력될 때, 새로운 view를 구성하면서 문자열을 자르고 출력시킬 수 있다.



또다른 활용으로는 index 와 row 를 이용한 순서 바꾸기(reverse) 이다.


=INDEX(ArrayFormula('sheet'!B$2:B),COUNTA(ArrayFormula('sheet'!$B$2:$B))-ROW()+2,1)


해당 예제는 2행 부터 시작되는 경우이고, arrayformula를 사용하는 시트도 2행부터 시작하여 내용을 맞췄다.


C 컬럼의 경우 그대로 복사하면, 옆의 행을 참조하도록 상대 주소가 반영된다.


3행의 경우도 전체 참조내용에서 row 함수에 의해 index 가 반전되므로 역정렬된 데이터를 볼 수 있다.


구글 form의 고질적인 문제(아래로 쌓이면 내용 확인을 위해 스크롤)가 있어 찾아봤다.

lispro06 (비회원)
    • 글자 크기

댓글 달기

[DROWN] Decrypting RSA with Obsolete and Weakened eNcryption

[원문보기]

DROWN 취약점이란  “Decrypting RSA with Obsolete and Weakened eNcryption: 취약한 구식 암호화법을 통한 RSA 복호화”에서 따온 이름으로, SSLv2취약점을 악용한 교차 프로토콜 공격입니다.


http://blog.alyac.co.kr/554


POODLE 과 RC4 관련 취약점 들을 제거하더라도 Openssl 관련 취약점이 계속 나오고 있다.


Heartbleed 는 시작이었다.



apache2 현재 Apache/2.2.22 (Ubuntu)  OpenSSL 1.0.1 14 Mar 2012 에서 아래 옵션을 사용해 봤으나 TLSv1.1 이 잘 못 되었다는데, 해결은 추후에 해야겠다.


SSLProtocol -all +TLSv1.1 +TLSv1.2

SSLCipherSuite HIGH:!aNULL:!MD5:!SSLv2:!SSLv3:!TLSv1


RC4는 


SSLProtocol all -SSLv2 -SSLv3

SSLHonorCipherOrder on

SSLCipherSuite "EECDH+ECDSA+AESGCM EECDH+aRSA+AESGCM EECDH+ECDSA+SHA384 EECDH+ECDSA+SHA256 EECDH+aRSA+SHA384 EECDH+aRSA+SHA256 EECDH+aRSA EECDH EDH+aRSA !aNULL !eNULL !LOW !3DES !MD5 !EXP !PSK !SRP !DSS"


위와 같이 하면 된 듯 하다.


RC4.png


보안서버가 아래와 같이 무료로 사용할 수 있지만, 설정에 따라 취약할 수 있으니, 이 점에 주의해야 한다.

무료 점검 해주는 사이트들이 많아 좋기는 한데, 설정을 강화해야 하는 번거로움이 있다.


 

 

COMODO

Lets encrypt

Start SSL

금액

도메인 당 5만원 내외

무료

 무료

사용기간

2년/1년

3개월(90일)

1년(365일)

의존성

 

openssl, git, python, gcc, etc…..(자동설치)

 

발급기관

verisign, comodo, …..

Mozilla, …….. sponsored by Google, Facebook, CISCO….

StartCom

지원서버

Apache, nginx, IIS, …..

Apache, nginx, iis(unstable), ?

Apache, IIS, …..

멀티도메인

별도 지원

일반적으로 어려움

유료 지원

[C] epochtime double 형, sprintf

[원문보기]
  char tseed[100];
  CString csID;
  time_t timer;
  struct tm y2k;
  double seconds;

  y2k.tm_hour = 0;   y2k.tm_min = 0; y2k.tm_sec = 0;
  y2k.tm_year = 70; y2k.tm_mon = 1; y2k.tm_mday = 1;

  time(&timer);  /* get current time; same as: timer = time(NULL)  */

  seconds = difftime(timer,mktime(&y2k));
  sprintf( tseed, "%s%.f", csID, seconds );

csID라는 CString 형과 epoch time(unixtime)을 tseed라는 char형에 넣으려고 1970년 1월 1일 기준을 difftime으로 구해 넣었다.
time(&timer)로 나오는 값은 long형인데, 활용이 잘 되지 않아, 이렇게 되었다.
비효율적이지만, 어쩔 수 없다.

[bWAPP] bWAPP - Broken Authentication

[원문보기]

A2 - Broken Auth. & Session Mgmt.

bWAPP - Broken Authentication


소스코드의 tonystark/I am Iron Man 을 입력하여 로그인한다.


A2BA-ILF.PNG

[bWAPP] iFrame injection

[원문보기]

A1 - Injection

iFrame injection


iframei.php?ParamUrl=robots.txt&ParamWidth=250&ParamHeight=250


ParamUrl 에 경로에 존재하는 파일을 넣으면 내용 확인 및 다운로드가 가능하다.


다운로드되는 파일은 portal.zip 이고, 나머지 php 파일 등은 렌더링되어 나오므로 파일 다운로드로 보기는 어렵다.


portal.bak, bugs,txt, 666 은 텍스트 형식이므로 내용 확인이 가능하다.


A1IFR.PNG


이를 소개한 동영상에서는 width, height를 바꾸거나 외부 경로 입력을 테스트 했다.

[구글핏] fitnees API 를 이용한 구글 스프레드시트로 데이터 가져오기

[원문보기]

https://ithoughthecamewithyou.com/post/export-google-fit-daily-steps-to-a-google-sheet

 

위 사이트를 참고해 진행한다.

 

1) 일단 코드를 다운로드 하고, API 콘솔을 이용해 https://console.cloud.google.com/apis 새로운 프로젝트를 만든다.(기존 프로젝트 이용 가능)

2) API 및 서비스 사용 설정에서 fitnees API 를 활성화 시킨다.

3) 사용자 인증정보에서 사용자 인증 정보 만들기를 선택한다.

4) OAuth 클라이언트 ID를 선택하고 애플리케이션 유형을 웹 애플리케이션으로 한다.

5) 이름을 "GF" 등으로 설정하고 승인된 리디렉션 URI 에 https://script.google.com/macros/d/{SCRIPTID}/usercallback 를 입력한다.

 

6) {SCRIPTID} 를 입력하기 위해 구글 드라이브에서 스프레드시트를 만들고, 스크립트 편집기를 열어 1)의 코드를 저장한 뒤, URL으 확인한다.

7) URL에 나온 스크립트 경로가 {SCRIPTID} 이다.

8) OAuth 클라이언트 ID 만들기를 선택하면 6)에서 저장한 코드에 Client ID, Client Secret을 입력할 수 있는 클라이언트 ID, 클라이언트 보안 비밀은 얻을 수 있다.

9) 저장이 끝나면 시트를 새로고침하여 OnOpen 함수가 자동 동작하도록 하여 Google Fit 메뉴를 확인한다.

10) Authorize...... 를 시작으로 시트이름을 "Metrics"{History}으로 수정하여 구글 피트니스에 저장된 데이터를 가져올 수 있다.

 

코드를 보면 사용하는 시트이름이 다음과 같다. 두 개의 시트를 생성하여 AppendRow null 오류를 방지한다.

 

function getMetrics() {

  getMetricsForDays(1, 1, 'Metrics');

}

 

function getHistory() {

  getMetricsForDays(1, 60, 'History');

}

 

fitnees.png

 

cd.png

 

 

[bWAPP] Server-Side Includes (SSI) Injection

[원문보기]

A1 - Injection

Server-Side Includes (SSI) Injection


LoadModule 을 지원하는 환경에서 가능하다


입력 필드에 <!--#echo var="DOCUMENT_ROOT" --> 를 넣었을 때, 아래와 같이 나오면 LoadModule이 지원 안되는 것이다.

실행 자체가 안 되니 의미가 없다.

<p>Hello 11<!--#echo Var="DOCUMENT_ROOT" --> 11,</p><p>Your IP address is:</p><h1><!--#echo var="REMOTE_ADDR" --></h1>

http://lispro06.woweb.net/infra/51326 참고

* 그동안 cgi 로 혼동했다. T.T;;

[bAWPP] HTML Injection - Stored (Blog)

[원문보기]

A1 - Injection

HTML Injection - Stored (Blog)


XSS 저장 방식이다.


게시판에 테스트 하듯이 스크립트 구문을 바로 입력하면 된다.


A1XSS-BLG.PNG


html 인젝션은 <h1>bee</h1><h2>bug</h2> 를 넣으면 된다.

[bWAPP] OS Command Injection [blind]

[원문보기]

A1 - Injection

OS Command Injection


동영상에서는 ; 등으로 테스트 하는데, windows 서버라 | (pipe, vertical var)로 하면 된다.


A1OSC.PNG


blind 의 경우,


명령어 >> 1.txt


로 파일을 만들어 해당 파일을 접근할 수 있다.


ren 이나, copy 명령어를 사용해 파일을 바꾸거나 txt 확장자로 교체해 소스 확인도 가능할 듯 하다.


del은 쓰지 말자.

위키백과 QA API X AWS lambda X API Gateway X SLACK

[원문보기]

공공 인공지능 오픈 API·DATA 서비스 포털의 위키백과 QA API를 aws 람다로 node.js 를 이용해 slack에서 받을 수 있도록 처리했습니다.

 

전체적인 내용은 https://blog.aliencube.org/ko/2016/05/15/slack-github-integration-with-aws-lambda/ 를 참고하였습니다.

http://www.usefulparadigm.com/2016/04/06/creating-a-slack-bot-with-aws-lambda-and-api-gateway/

https://gist.github.com/sjoonk/20ae13e5cd8be88e9824e3bad11b2859

 

http://aiopen.etri.re.kr/service_list.php 

 

s.png

 

 

exports.handler = (event, context) => {

    // Sets request options

    var options = {

        host: 'aiopen.etri.re.kr',

        port: '8000',

        path: '/WikiQA',

        method: 'POST',

        headers: {

          'Content-Type': 'application/json'

        }

    };

    var access_key = '발급받은키';

    var type = 'irqa';

    // Sets the request body    

    var data = {

        'access_key': access_key,

        'argument': {

            'question': event.text,

            'type': type

        }

    };

    var request = require('http');

    var req = request.request(options, function (res) {

      var chunks = [];

    

      res.on("data", function (chunk) {

        chunks.push(chunk);

      });

    

      res.on("end", function () {

        var body = Buffer.concat(chunks);

        console.log(body.toString());

        body = JSON.parse(body);

        console.log(body.result);

        if(body.result==0){

          var text = body.return_object.WiKiInfo.IRInfo[0].sent;

          var ans = body.return_object.WiKiInfo.AnswerInfo[0].answer;

        }else{

          var text = "없음";

          var ans = event.text;

        }

          context.succeed({

            "response_type": "in_channel",

            "text": "ETRI 위키백과 QA API 결과 : " + ans,

            "attachments": [

                {

                    "text": "https://ko.wikipedia.org/wiki/" + encodeURI(ans) + "\n" + text,

                    "color": "#7CD197"

                }

            ]

          });

      });

    });

    req.write(JSON.stringify(data));

    req.end();

};

 

 

aws gateway 에서 매핑템플릿에 application/x-www-form-urlencoded 를 추가하지 않으면, json 요청 값을 처리할 수 없으니, 꼭 추가하자.

(event undefined)

## convert HTML POST data to JSON
 
## get the raw post data from the AWS built-in variable and give it a nicer name
#set($rawAPIData = $input.path('$'))

## first we get the number of "&" in the string, this tells us if there is more than one key value pair
#set($countAmpersands = $rawAPIData.length() - $rawAPIData.replace("&", "").length())
 
## if there are no "&" at all then we have only one key value pair.
## we append an ampersand to the string so that we can tokenise it the same way as multiple kv pairs.
## the "empty" kv pair to the right of the ampersand will be ignored anyway.
#if ($countAmpersands == 0)
 #set($rawPostData = $rawAPIData + "&")
#end
 
## now we tokenise using the ampersand(s)
#set($tokenisedAmpersand = $rawAPIData.split("&"))
 
## we set up a variable to hold the valid key value pairs
#set($tokenisedEquals = [])
 
## now we set up a loop to find the valid key value pairs, which must contain only one "="
#foreach( $kvPair in $tokenisedAmpersand )
 #set($countEquals = $kvPair.length() - $kvPair.replace("=", "").length())
 #if ($countEquals == 1)
  #set($kvTokenised = $kvPair.split("="))
  #if ($kvTokenised[0].length() > 0)
   ## we found a valid key value pair. add it to the list.
   #set($devNull = $tokenisedEquals.add($kvPair))
  #end
 #end
#end
 
## next we set up our loop inside the output structure "{" and "}"
{
#foreach( $kvPair in $tokenisedEquals )
  ## finally we output the JSON for this pair and append a comma if this isn't the last pair
  #set($kvTokenised = $kvPair.split("="))
 "$util.urlDecode($kvTokenised[0])" : #if($kvTokenised[1].length() > 0)"$util.urlDecode($kvTokenised[1])"#{else}""#end#if( $foreach.hasNext ),#end
#end
}

[QT] 트레이아이콘(TrayIcon)사용하기

[원문보기]

 

http://browniz1004.blog.me/220956638885

 

qt 트레이 showMinimized() tray -> 나의 검색어

 

[헤더파일]

 

QSystemTrayIcon *TrayIcon;  //전역변수

QMenu *TrayIconMenu;

 

private slots:

void onSystemTryIconClicked(QSystemTrayIcon::ActivationReason); //트레이아이콘 클릭시 이벤트 설정

void on_actionExit_triggered(); //트레이아이콘 메뉴설정시 사용

 

 

private: //프로그램종료시, 프로그램 숨김시 이벤트설정

void closeEvent(QCloseEvent *event);

void hideEvent(QHideEvent *event); 

 

 

[소스파일]

TrayIcon = new QSystemTrayIcon(this);

 

TrayIconMenu = new QMenu(this);

 

TrayIconMenu->addAction(ui.actionExit);

TrayIconMenu->addSeparator();

TrayIcon->setContextMenu(TrayIconMenu);

QIcon Icon(":/appMain/Resources/icon_menu_01.png"); //아이콘은 기존 리소스 경로로 지정

TrayIcon->setIcon(Icon);

TrayIcon->show();

TrayIcon->setToolTip(tr("DFC")); //트레이아이콘에 마우스 움직였을때 문구

TrayIcon->showMessage(tr("DFC"), tr("DFC."), QSystemTrayIcon::Information, 5000); //트레이아이콘 처음 적용시 설명

connect(TrayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(onSystemTryIconClicked(QSystemTrayIcon::ActivationReason)));

 

 

함수 선언부

void appMain::onSystemTryIconClicked(QSystemTrayIcon::ActivationReason reason)

{

switch (reason)

{

case QSystemTrayIcon::Trigger:

case QSystemTrayIcon::DoubleClick:

this->setWindowState(Qt::WindowActive);

this->show();

break;

}

}

 

void appMain::hideEvent(QHideEvent *event)

{

if (isMinimized())

{

this->hide();

}

QWidget::hideEvent(event);

}

void appMain::closeEvent(QCloseEvent *event)

{

if (TrayIcon->isVisible())

{

TrayIcon->hide();

}

}

void appMain::on_actionExit_triggered()

{

this->hide();

this->close();

}

[GS] Go To Lastrow Ctrl+↓

[원문보기]

구글 스프레드시트에서 마지막 행으로 이동하는 방법은 단축키로 가능하다.


그러나 단축키에 익숙하지 않다면 구글 스크립트를 메뉴에 등록해 놓고 사용하도록 세팅해 놓는 것이 정신 건강에 좋을 때도 있다.


현재 선택된 시트에서 가장 아래 행으로 이동하는 스크립트이다.


많이 쓰는 기능이므로 잘 보이는 곳에 적어두면 찾기 쉽다.


function myFunction() {

  var sh = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();

  var lr = sh.getLastRow();

  var pos = sh.getRange(lr, 1, 1, 1);

  sh.setActiveSelection(pos);

}

function onOpen() {

  var ui = SpreadsheetApp.getUi();

  // Or DocumentApp or FormApp.

  ui.createMenu('MITLab')

      .addItem('아래로 이동(Ctrl+↓)', 'myFunction')

      .addToUi();

}

[pull챗봇] 행아웃 X Google Spreadsheet with Apps script

[원문보기]
구글의 예제코드는 공개되어 있으며, 단순 응답으로 되어 있다.
 
구글 앱스 스크립트(GS)를 주로 스프레드 열람 등에 썼기 때문에, 특정 시트 값을 가져오는 것은 너무나 익숙하다.
 
 /**
 * Responds to a MESSAGE event in Hangouts Chat.
 *
 * @param {Object} event the event object from Hangouts Chat
 */
function onMessage(event) {
  var name = "";
  if (event.space.type == "DM") {
    name = "You2";
  } else {
    name = event.user.displayName;
  }
  var ss = SpreadsheetApp.openById("시트ID");
  var s1 = ss.getSheetByName("시트2");
  var r1 = s1.getRange(2, 1, 3, 4);
  var v1 = r1.getValues();
  var message = name + " said "" + event.message.text + """;
  message = message + v1.join(" ");
  return { "text": message };
}
/**
 * Responds to an ADDED_TO_SPACE event in Hangouts Chat.
 *
 * @param {Object} event the event object from Hangouts Chat
 */
function onAddToSpace(event) {
  var message = "";
  if (event.space.type == "DM") {
    message = "Thank you for adding me to a DM, " + event.user.displayName + "!";
  } else {
    message = "Thank you for adding me to " + event.space.displayName;
  }
  return { "text": message };
}
/**
 * Responds to a REMOVED_FROM_SPACE event in Hangouts Chat.
 *
 * @param {Object} event the event object from Hangouts Chat
 */
function onRemoveFromSpace(event) {
  console.info("Bot removed from ", event.space.name);
}
 
다른 점은 배포 방식인데, 매니페스트에서 배포를 선택해야 한다.
 
re.jpg

 

 
배포된 ID를 구글 클라우드 콘솔에서 Hangouts Chat API 구성에 추가한다.
 
id.jpg

 

[구글 클라우드 콘솔 Hangouts Chat API 구성]
cons.jpg

 

 
해당 작업이 완료되면 채팅방에서 봇에게 말을 걸도록 추가해 줘야 한다.
 
기존 행아웃이 아닌 chat.google.com 으로 진행해야 하며, 모바일 앱 역시 행아웃 채팅이란 앱을 설치해야 한다.
 
좌측 상단의 사용자, 채팅방, 봇 찾기를 누르고 설정한 이름이 정상적으로 보이면 성공한 것이다.
 
스프레드시트 열람 권한을 얻는 것까지 절차를 거치면, 봇에게 스프레드시트의 내용을 보여주도록 할 수 있다.
 
1.jpg

 

 
hc.jpg

 

  

[R] 우분투 16.04에 RStudio 설치

[원문보기]

아마존 t2.micro에 RStudio를 설치해서 원격으로 접속해 본다.

 

터미널보다 실행 속도가 더 빠르다니 의아하다.

 

http://download2.rstudio.org/ 에서 rstudio-server-1.1.463을 설치했다.

 

http://infondgndg91.blogspot.com/2016/09/1604-lts-rstudio.html 등에서는 rstudio-0.99.896-amd64.deb 를 받으라고 하는데,

 

Package 'libssl0.9.8' has no installation candidate 에러가 발생하여 상위 버전으로 설치했다.

 

 

  422  wget http://download2.rstudio.org/rstudio-server-1.1.463-amd64.deb

  423  sudo gdebi rstudio-server-1.1.463-amd64.deb

 

 

이상 없으면 아래와 같이 출력되며, 자동 실행된다.

 

Reading package lists... Done

Building dependency tree

Reading state information... Done

This package is uninstallable

Wrong architecture 'i386'

ubuntu@ip-172-31-29-250:~$ wget http://download2.rstudio.org/rstudio-server-1.1.463-amd64.deb

--2019-04-10 00:12:20--  http://download2.rstudio.org/rstudio-server-1.1.463-amd64.deb

Resolving download2.rstudio.org (download2.rstudio.org)... 54.239.186.77, 54.239.186.152, 54.239.186.198, ...

Connecting to download2.rstudio.org (download2.rstudio.org)|54.239.186.77|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 63566904 (61M) [application/x-deb]

Saving to: ‘rstudio-server-1.1.463-amd64.deb’

 

rstudio-server-1.1.463-amd64.deb        100%[=============================================================================>]  60.62M  13.8MB/s    in 5.6s

 

2019-04-10 00:12:26 (10.7 MB/s) - ‘rstudio-server-1.1.463-amd64.deb’ saved [63566904/63566904]

 

ubuntu@ip-172-31-29-250:~$ sudo gdebi rstudio-server-1.1.463-amd64.deb

Reading package lists... Done

Building dependency tree

Reading state information... Done

Reading state information... Done

 

RStudio Server

 RStudio is a set of integrated tools designed to help you be more productive with R. It includes a console, syntax-highlighting editor that supports direct code execution, as well as tools for plotting, history, and workspace management.

Do you want to install the software package? [y/N]:y

Selecting previously unselected package rstudio-server.

(Reading database ... 106368 files and directories currently installed.)

Preparing to unpack rstudio-server-1.1.463-amd64.deb ...

Unpacking rstudio-server (1.1.463) ...

Setting up rstudio-server (1.1.463) ...

groupadd: group 'rstudio-server' already exists

rsession: no process found

Created symlink from /etc/systemd/system/multi-user.target.wants/rstudio-server.service to /etc/systemd/system/rstudio-server.service.

● rstudio-server.service - RStudio Server

   Loaded: loaded (/etc/systemd/system/rstudio-server.service; enabled; vendor preset: enabled)

   Active: active (running) since Wed 2019-04-10 00:12:41 UTC; 1s ago

  Process: 25430 ExecStart=/usr/lib/rstudio-server/bin/rserver (code=exited, status=0/SUCCESS)

 Main PID: 25434 (rserver)

    Tasks: 3

   Memory: 14.3M

      CPU: 387ms

   CGroup: /system.slice/rstudio-server.service

           └─25434 /usr/lib/rstudio-server/bin/rserver

 

Apr 10 00:12:41 ip-172-31-29-250 systemd[1]: Starting RStudio Server...

Apr 10 00:12:41 ip-172-31-29-250 systemd[1]: Started RStudio Server.

 

 

8787 포트를 방화벽에서 허용하여 접속하면, 윈도우에 설치한 RStudio와 동일하게 사용가능 하다.

 

 

 

[push챗봇] 구글 앱스 스크립트 X 행아웃 채트(구글 채트)

[원문보기]

행아웃 채트가 구글채트로 이름이 변경되었다.

 

개별 도메인 사용자만 이용할 수 있는데, 무료 계정도 모바일은 가능하다.

(chat.google.com) 로 접속하면 PC에서도 이용 가능하고 대화방의 이름을 얻을 수 있기 때문에, 6의 예제 코드에 space.name 에 하드 코딩 가능하다.

 

https://suritam9.pe.kr/index.php?mid=imp&document_srl=1405 에서 이미 대화형 봇을 다뤘으며, 이번 건은 push형이다.

 

그동안은 integramat 이나 다른 수단을 이용했는데, 구글 앱스 스크립트로 바로 가능한 방법이 있어 시도해 봤다.

 

https://medium.com/@stephane.giron/send-push-message-to-hangouts-chat-with-apps-script-274ddadcbc55

 

1. 구글 클라우드 플랫폼 서비스 계정에서 계정 생성 및 키를 만든다.(JSON 형태 다운로드 파일 보관)

2. 앱스 스크립트 라이브러리에서 Oauth2 를 설치하는데, 1B7FSrk5Zi6L1rSxxTDgDEUsPzlukDsi4KGuTMorsTQHhGBzBkMun4iDF 로 검색한다.

3. 1에서 다운 받은 파일에 PRIVATE_KEY 와 CLIENT_EMAIL를 복사하고 서비스 생성 스크립트를 실행시킨다.

 

var PRIVATE_KEY = '-----BEGIN PRIVATE KEY-----\n...\n-----END PRIVATE KEY-----\n';
var CLIENT_EMAIL = '...';
/**
* Configures the Chatbot service.
*/
function getChatbotService() {
return OAuth2.createService(‘MyChatBot’)
// Set the endpoint URL.
.setTokenUrl(‘https://accounts.google.com/o/oauth2/token')
// Set the private key and issuer.
.setPrivateKey(PRIVATE_KEY)
.setIssuer(CLIENT_EMAIL)
// Set the property store where authorized tokens should be persisted.
.setPropertyStore(PropertiesService.getScriptProperties())
// Set the scope.
.setScope(‘https://www.googleapis.com/auth/chat.bot');
}

4. 토큰이 발행되는지 테스트 한다.

/**
* Test for getting access token
*/
function getAccessTokenTest() {
var service = getChatbotService();
if (service.hasAccess()) {
Logger.log(service.getAccessToken());
} else {
Logger.log(service.getLastError());
}
}

5. 참고 URL 에 빠져 있는 부분인데, 봇을 만들어 채팅방에 추가해야 한다. (봇 만들기는 다른 사이트를 검색하여 아이콘 등을 설정한다.)

권한은 도메인 내로 해야 head 배포 id 사용이 가능하다.

image.png

배포 id는 게시에 메니페스트에서 배포를 선택하여 lastesthead deployment 배포에서 getid 를 선택하여 확인한다.

0.png

 

 

6.  예제 코드를 이용해 해당 채팅방에 메시지를 보내본다.

 

/**
* Authorizes and makes a request to the Hangouts Chat API for :
* - Getting all spaces the bot is installed
* - Sending message when space is a Direct Message space
*/
function sendPushMessage() {
var service = getChatbotService();
if (service.hasAccess()) {
//WE retrieve all the spaces bot has been added
var url = 'https://chat.googleapis.com/v1/spaces';
var response = UrlFetchApp.fetch(url, {
headers: {
Authorization: 'Bearer ' + service.getAccessToken()
}
});
var rep = JSON.parse(response.getContentText());
if(rep.spaces && rep.spaces.length > 0){
for(var i = 0; i < rep.spaces.length; i++) {
var space = rep.spaces[i];
if(space.type == "DM"){
//We send message only to Direct Message room.
var url = 'https://chat.googleapis.com/v1/'+space.name+'/messages';

var options = {
method : 'POST',
contentType: 'application/json',
headers: {
Authorization: 'Bearer ' + service.getAccessToken()
},
payload : JSON.stringify({ text: "Hello world !" })
}

//We send message to the DM room
UrlFetchApp.fetch(url, options);
}else{
//If Type is 'ROOM' or 'TYPE_UNSPECIFIED' we don't send notification.
}
}
}else{
Logger.log('Bot is not added to any spaces');
}
} else {
Logger.log(service.getLastError());
}
}

 

7. 오류가 발생한다면 구글 개발자 콘솔에서 행아웃 채트 API 활성화를 누락했거나, 채팅방이 잘 확인되는지, space 에 대한 참여 멤버, 대화방 명 등을 확인해 보면 디버깅에 도움이 된다.

https://developers.google.com/hangouts/chat/reference/rest/v1/spaces

https://developers.google.com/hangouts/chat/reference/rest/v1/spaces.members

https://developers.google.com/hangouts/chat/reference/rest/v1/spaces.messages

 

[R] 구글 플레이스토어 리뷰 별점까지 수집

[원문보기]

도커에 타임존을 변경해서 실행한다.

 

sudo docker run -v /etc/localtime:/etc/localtime:ro -p 4445:4444 selenium/standalone-chrome &

sudo docker ps -a

sudo docker exec -it 911cca8e9f44 /bin/bash

seluser@911cca8e9f44:/$ date

Fri Apr 19 11:31:47 KST 2019

 

Rscript로 실행할 때는 library를 주석처리하고

Rscript --default-packages=methods,utils,httr,stringr,rvest,RSelenium 파일명.r

으로 실행한다.

 

library(rvest)

library(RSelenium)

library(httr)

library(stringr)

 

remDr <- remoteDriver(port = 4445L, browserName = "chrome")

remDr$open() #크롬 Open

 

remDr$navigate("https://play.google.com/store/apps/details?id={패키지명}&showAllReviews=true&hl=ko") #설정 URL로 이동

 

webElemButton <- remDr$findElements(using = "xpath", "/html/body/div[1]/div[4]/c-wiz/div/div[2]/div/div[1]/div/div/div[1]/div[2]/c-wiz/div/div/div[1]/div[1]/div[3]/content")

 

remDr$mouseMoveToLocation(webElement = webElemButton[[1]]) #정렬 방법 리스트 확장

 

remDr$click()

 

Sys.sleep(1)

 

webElemButton <- remDr$findElements(using = "xpath", "/html/body/div[1]/div[4]/c-wiz/div/div[2]/div/div[1]/div/div/div[1]/div[2]/c-wiz/div/div/div[2]/div[1]")

 

remDr$mouseMoveToLocation(webElement = webElemButton[[1]]) #최신순 선택

 

remDr$click()

 

Sys.sleep(10)

 

 

frontPage <- remDr$getPageSource() #페이지 전체 소스 가져오기

 

reviewNames <- read_html(frontPage[[1]]) %>% html_nodes('.bAhLNe.kx8XBd') %>% html_nodes('.X43Kjb') %>%  html_text() #페이지 전체 소스에서 리뷰 정보(이름, 날짜) 부분 추출하기 

 

reviewDates <- read_html(frontPage[[1]]) %>% html_nodes('.bAhLNe.kx8XBd') %>% html_nodes('.p2TkOb') %>%  html_text() #페이지 전체 소스에서 리뷰 정보(이름, 날짜) 부분 추출하기 

 

reviewComments <- read_html(frontPage[[1]]) %>% html_nodes('.UD7Dzf') %>%  html_text() #페이지 전체 소스에서 리뷰 정보(이름, 날짜) 부분 추출하기

 

reviewStars <- read_html(frontPage[[1]]) %>% html_nodes('.nt2C1d') %>% html_nodes('.pf5lIe') %>% html_children() %>% html_attr("aria-label") #페이지 전체 소스에서 리뷰 정보(이름, 날짜) 부분 추출하기

 

reviewData <- data.frame(name=reviewNames, date=reviewDates, comment=reviewComments, stars=reviewStars)

 

 

write.csv(reviewData, "sh.csv")

 

 

remDr$close()

stars.png

 

 

 

 

https://stat4701.github.io/edav/2015/04/02/rvest_tutorial/

 

[R] AWS에 도커로 Shiny server 설치 후 googleAuthR 을 이용

[원문보기]

AWS t2.micro 에서 R을 이용한 shiny 패키지 설치가 잘 되지 않는다.

 

그래서 shiny server를 설치하더라도 3838포트는 접속 되지만 shiny app 은 실행시킬 수 없다.

 

sudo snap install docker 

sudo docker pull rocker/shiny-verse

도커 설치 후 실행한 뒤 (여기까지는 https://wikidocs.net/66611 사이트 참고)

 

sudo docker container run -d -p 3838:3838 rocker/shiny-verse

sudo docker container ls

sudo docker exec -it 컨테이너명 or ID /bin/bash

 

쉘로 들어간 다음에

R 을 실행시키고 명령 프롬프트에서 install.packages("googleAuthR") 으로 googleAuthR 패키지를 설치한다.

 

그 후 home 폴더 하위에 디렉터리를 생성하고, app.R 파일을 만들어 소스를 저장한다.

 

기존 도커를 종료 시키고 저장한 앱을 실행시키면 추가 패키지로 인한 오류 때문에 실행되지 않은 앱들의 문제를 해결 할 수 있다.

 

sudo docker container stop 컨테이너명 or ID

sudo docker run --rm -d -p 3838:3838 -v /home/ubuntu/[폴더명]:/srv/shiny-server/[앱이름] rocker/shiny-verse

 

shiny-welcome.png

 

[GS] 다중 행에 사용자 정의 함수 사용

[원문보기]

사용자 정의 함수는 gs 파일에 선언하여 사용 가능하다.


그런데, 그 호출 횟수가 너무 늘어나게 되면, Loading 이라고 표시되며 제대로 실행되지 않는다.


이럴 때, 최상단에 사용자 정의함수를 재정의하여 다중 행을 처리할 수 있는 선언을 사용할 수 있다.


원래 아래 함수는 dtr2 부분에 eval로 되어 있었고, 이름으 doEval인 함수였다.(인터넷 예제)

function dtr( formula ) {

if (typeof formula.map === "function") {

return formula.map(dtr);

}else if(formula){

return dtr2(formula);

}

}


붉은 부분은 스프레드 시트에서 사용할 호출 함수의 이름이다.


파란색 함수는 원래 기능을 수행할 아래 함수이다. 즉, 사용자 정의 함수가 되겠다.


스프레드 시트에서 아래 함수를 직접 호출하여 사용 가능하나, 호출이 100개 이상 되면 오류가 발생한다.


아래의 사용자 정의 함수는 ifftt의 datetime 문자열을 google의 datetime 으로 바꾸는 것으로 이벤트가 쌓일 때마다 늘어난다. 처음에는 직접 호출 가능하나 추후 오류가 발생하므로, E 컬럼에 =dtr(A1:A) 로 정의해 준다.


ABCDE

January 02, 2018 at 08:52AMentered2018-01-022018. 1. 2 오전 8:52:00


function dtr2(myDate){

  var vv = myDate;

  

  vv = vv.toString();

  

  var va = vv.split(" at ");

  if(va[1]==undefined){

    return;

  }

  var ampm = va[1].split(":");

  

  if(va[1].substr(-2)=="PM"){

    myDate = new Date((va[0].replace(",","")+", "+(parseInt(ampm[0],10)+12)+":"+ampm[1].substr(0,2)+":00"));

  }else{

    myDate = new Date((va[0].replace(",","")+", "+parseInt(ampm[0],10)+":"+ampm[1].substr(0,2)+":00"));

  }

  return myDate;

}

[TF] 파이썬과 케라스를 이용한 딥러닝/강화학습 주식투자

[원문보기]

도서 [파이썬과 케라스를 이용한 딥러닝/강화학습 주식투자] 에 나온 예제를 실행해 봤다.

 

현재기준으로 아나콘다 3을 설치하면 python 3.8.x 가 설치되며, python path를 설정해야 제대로 실행 가능하다.

 

기존 2.7, 3.5 가 설치된 환경이라 여러 버전이 섞여서 다양한(?) 에러를 발생시켰다.

 

시스템 환경변수에 아래를 등록한다.

PYTHONPATH

c:\programdata\anaconda3;c:\programdata\anaconda3\Lib;c:\programdata\anaconda3\DLLs;c:\programdata\anaconda3\libs;c:\programdata\anaconda3\Scripts;c:\programdata\anaconda3\bin

 

알수 없는 오류 (set_session, get_default_graph())에 대해 대략 아래와 같이 수정하여 아웃풋을 얻었다.

 

[networks.py]

23 from tensorflow.keras.backend import set_session -> from tensorflow.keras.backend import clear_session

25 graph = tf.get_default_graph() -> graph = tf.compat.v1.get_default_graph()

 

시간이 지나면 각종 로그와 그림에 대해 이해하게 되겠지.

 

epoch_summary_003.png

 

 

[챗봇] 대화형 질의 응답 만들기

[원문보기]

대화형 챗봇을 통해 문자열 입력시 대답하도록 한다.

 

채팅방에서 실행하게 되면, @봇이름 대화 형식으로 하고, DM일 경우 문자열을 입력하기만 하면 응답한다.

 

 

https://cloud.google.com/blog/products/g-suite/building-a-google-hangouts-chatbot-using-apps-script

 

[채팅방]

at.png

[DM]

 

DM.png

 

https://github.com/gsuitedevs/hangouts-chat-samples/blob/master/apps-script/vote-text-bot/vote-text-bot.js

 

투표하기 코드를 조금 고쳐서 스프레드시트에 응답 결과를 저장하도록 했다.

클릭 횟수를 프로세스의 단위로 삼아 1번 질문, 2번 질문, ...  n번 질문 후 마지막에 앞으로 돌아가도록 했다.

 

이 설문의 문제는 스프레드시트 쓰기 권한이 oAuth 로 승인되어야 해서 스크립트를 실행하여 권한을 얻어야 하는 문제가 있다.

 

ar.png

 

배포된 스크립트로 하는게 아닌 메니페스토에서 배포라서 스크립트를 작성한 사용자의 권한을 대행하지 못하는 것 같다.

 

권한 문제가 있어 설문으로 활용할 방법에 대해 좀 더 고민해 봐야겠다.

 

또한 다른 도메인 사용자 일때도 안 되는 것 같다.

 

글로벌 권한이 있는 계정으로 다시 만들어 테스트 해봐야 겠다.

 

rs.png

 

 

[이클립스] tomcat 404, spring, web API

[원문보기]

스프링 기반으로 개발하여, 디스패처 서블릿을 WEBXML 에 MVC 방식으로 매핑하여 개발하였을 때, 많은 복잡성이 발생한다.

 

톰캣의 배포된 실행 패키지를 정상 종료 시키지 않고 삭제하면, LOCK 이 걸려 재 컴파일해서 RUN 하더라도 쉽게 원하는 패키지가 실행되지 않는다.

 

그 때는 아예, 톰캣 서버를 완전히 지우고, 새로 서버를 만들어 실행한다.

 

api.png

 

이전 1 ... 3 4 5 6 7 8 9다음
첨부 (1)
api.png
28.3KB / Download 30
위로