typetalk의bot API로 투고하고 싶어요.
하고 싶은 일
추진 방법
BOT+API Token 생성, 화제 ID 정보 얻기
topic.post
권한이 있으면 발언할 수 있음Typetalk Token
과bot의 화제를 제작한 URL에서 등TopicID
을 확인하고 저장한다.sample1.py: 개발 가이드 샘플 그대로 동작 확인
pip install requests
에 Requestshttp://requests-docs-ja.readthedocs.io/en/latest/user/install/ 가져오기Typetalk Token
과toipic id
가 있다면 먼저 시도해 볼 수 있다import requests
r = requests.post('https://typetalk.com/api/v1/topics/<topic id>?typetalkToken=<api token>', {'message':'Hello, Typetalk!'})
print r.status_code
print r.json()
실행python sample1.py
sample2.py: 표준 입력 가져오기 처리 추가
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import requests
import sys
topic_id='<topic id>'
api_token='<api token>'
def main():
lines = sys.stdin.readlines()
for i, line in enumerate(lines):
message = message + line
r = requests.post('https://typetalk.com/api/v1/topics/' + topic_id +'?typetalkToken=' + api_token, {'message': message})
r.status_code
r.json()
if __name__ == "__main__":
main()
사용법
sample2.py가 단독으로 실행할 수 있도록 실행 권한을 설정합니다
chmod +x sample2.py
echo "hogehoge" | sample2.py
cat에서 파일 내용 내보내기cat hoge.txt | sample2.py
명령 실행 결과 재생date "+%Y-%m%d" | sample2.py
참조 정보
Reference
이 문제에 관하여(typetalk의bot API로 투고하고 싶어요.), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/0xmks/items/444046ff5b2558fbb77f텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)