본문 바로가기

공부/리눅스

slackclient 라이브러리 추가(리눅스7.0)

반응형

서버 모니터링, 문자받기

 

slack api를 사용하기 위한 준비 단계 - centos 7.0환경

 

1/ 여기에서 Legacy token을 얻음(xoxp-로 시작하는 문자열)
legacy token으로 정보 전송에 사용

2/ python 최신버전 설치

3/ pip 설치

4/ pip install slackclient

 

사용 소스

##########################################################################
# NAME          : dj
# LAST UPDATE   : 2018-06-11
# Verersion     : 0.1
##########################################################################
from slackclient import SlackClient
sc = SlackClient("xoxp-")
sc.api_call("chat.postMessage", channel = "#general",text = 'im joke')

 

설치과정 순차적 설명

 

없는 package 설치

1. pip install pyldap

2. git clone https://github.com/lunaryorn/pyudev.git
   받은 폴더 안에서 python setup.py install

3. git clone https://github.com/rthalley/dnspython
   받은 폴더 안에서 python setup.py install

 

slackclient 설치

pip install slackclient

requests를 지워야한다는 내용이 있음

 

requests package 지우는 방법

 

[root@localhost test]# find / -name 'requests'
find: ‘/run/user/1000/gvfs’: 허가 거부
/var/lib/certmonger/requests
/usr/lib/python2.7/site-packages/pip/_vendor/requests
/usr/lib/python2.7/site-packages/requests

 

[root@localhost site-packages]# ls | grep request
requests
requests-2.6.0-py2.7.egg-info
[root@localhost site-packages]# pwd
/usr/lib/python2.7/site-packages
[root@localhost site-packages]# rm -rf requests-2.6.0-py2.7.egg-info

 

[root@localhost site-packages]# pip install slackclient
Collecting slackclient
Collecting requests<3.0a0,>=2.11 (from slackclient)
  Using cached https://files.pythonhosted.org/packages/49/df/50aa1999ab9bde74656c2919d9c0c085fd2b3775fd3eca826012bef76d8c/requests-2.18.4-py2.py3-none-any.whl
Requirement already satisfied: websocket-client<1.0a0,>=0.35 in /usr/lib/python2.7/site-packages (from slackclient) (0.48.0)
Requirement already satisfied: six<2.0a0,>=1.10 in /usr/lib/python2.7/site-packages (from slackclient) (1.11.0)
Requirement already satisfied: certifi>=2017.4.17 in /usr/lib/python2.7/site-packages (from requests<3.0a0,>=2.11->slackclient) (2018.4.16)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/lib/python2.7/site-packages (from requests<3.0a0,>=2.11->slackclient) (3.0.4)
Requirement already satisfied: idna<2.7,>=2.5 in /usr/lib/python2.7/site-packages (from requests<3.0a0,>=2.11->slackclient) (2.6)
Requirement already satisfied: urllib3<1.23,>=1.21.1 in /usr/lib/python2.7/site-packages (from requests<3.0a0,>=2.11->slackclient) (1.22)
Installing collected packages: requests, slackclient
Successfully installed requests-2.18.4 slackclient-1.2.1

완료~~~!

 

소스 실행하기

[root@localhost test]# python test.py

 

 

반응형