파이썬을 사용하여 텔레그램 채널에 메세지를 보내는 예제입니다.
<텔레그램 봇 토큰>과 <채널 ID> 부분은 아래 글에서 설명했던 값으로 바꿔줍니다.


–> 텔레그램 봇으로 채널 포스팅 - 1. 준비 작업


Python 2 :
# -*- coding: utf-8 -*-

import requests
 
url = "https://api.telegram.org/bot<텔레그램 봇 토큰>/sendMessage"
headers = {"Content-type": "application/json"}
params = '{"chat_id": "@<채널 ID>", "text": "test string [한글]"}'
r = requests.post(url, headers = headers, data = params)
 
print(r.text)
print(r.status_code)

Python 3 :
# -*- coding: utf-8 -*-

import requests
 
url = "https://api.telegram.org/bot<텔레그램 봇 토큰>/sendMessage"
headers = {"Content-type": "application/json"}
params = '{"chat_id": "@<채널 ID>", "text": "test string [한글]"}'
r = requests.post(url, headers = headers, data = params.encode("UTF-8"))
 
print(r.text)
print(r.status_code)


참고 글


<테스트 환경>
 - OS : Windows 7
 - Python 버전 : 2.7, 3.6
,


기본 HTTP 요청하기

import httplib

conn = httplib.HTTPConnection("httpbin.org")

conn.request("GET", "/ip")
r1 = conn.getresponse()
print r1.status, r1.reason
data1 = r1.read()
print data1

conn.request("GET", "/get")
r2 = conn.getresponse()
print r2.status, r2.reason
data2 = r2.read()
print data2

conn.close()
  • https 접속을 하려면, httplib.HTTPConnection 대신에 httplib.HTTPSConnection을 사용한다.

> conn = httplib.HTTPSConnection("httpbin.org")

  • 특정 포트 지정시는 아래와 같은 방법 중 한가지를 사용한다.

> conn = httplib.HTTPConnection("httpbin.org:80")

> conn = httplib.HTTPConnection("httpbin.org", 80)


POST 요청하기

import httplib, urllib

conn = httplib.HTTPConnection("httpbin.org")

params = urllib.urlencode({'spam': 1, 'eggs': 2, 'bacon': 0})
headers = {"Content-type": "application/x-www-form-urlencoded",
           "Accept": "text/plain"}
conn.request("POST", "/post", params, headers)
response = conn.getresponse()
print response.status, response.reason
data = response.read()
print data

params = "test string"
headers = {"Content-type": "text/html"}
conn.request("POST", "/post", params, headers)
response = conn.getresponse()
print response.status, response.reason
data = response.read()
print data

conn.close()


참고 사이트

  • http://httpbin.org : 각종 HTTP 요청들에 대한 응답을 테스트할 수 있는 사이트


<테스트 환경>

 - OS : Windows 7
 - Python 버전 : 2.7


,

사전 설치 요구사항

  • JDK 8
  • Eclipse EE버전


설치

  1. Eclipse를 실행한다.
  2. Help -> Eclipse Marketplace 메뉴를 실행한다.
  3. vaadin으로 검색한다.
  4. Vaadin Plugin for Eclipse를 설치한다.


프로젝트 생성

  1. File -> New -> Project 메뉴를 선택한다.
  2. Vaadin/Vaadin X Project 항목을 선택 후, 다음을 누른다.
  3. 프로젝트 명을 입력한다.
  4. 기본적인 예제 코드를 포함하는 프로젝트가 생성된다.


프로젝트 실행

  1. 프로젝트 오른쪽 클릭 후, Run As -> Run On Server 메뉴를 선택한다.
  2. Next 버튼을 누른다.
  3. 실행할 프로젝트를 왼쪽에서 오른쪽으로 이동 후, Finish 버튼을 누른다.


<테스트 환경>
OS : Windows 7
Eclipse 버전 : Mars
Vaadin Plug-in 버전 : 2.3.6
,


레퍼런스에 있는 내용이지만, 자주 까먹는 내용..


STL map 사용시, [] 연산자를 사용하여 참조를 할 때, 해당 엔트리가 없을 경우 엔트리가 추가된 후 NULL이 리턴된다.



map<A, B> some_map;


...


C = some_map[D];




엔트리가 추가되는 것을 원하지 않을 경우, find() 함수를 사용하여 미리 확인 후 참조하여야 한다.


if (some_map.find(D) != some_map.end()) {

  C = some_map[D];

}







,


참고 글


 - [Emacs] Emacs에서 package-install 기능 사용하기


 - [Emacs] Emacs에서 테마 적용 방법




Sublime Text 테마 적용하기


1) MELPA 서버가 추가된 상태에서, M-x를 누른 후, package-install을 입력한다.


2) 패키지명으로 monokai를 입력하여 설치한다.


3) M-x를 누른 후, load-theme를 입력한다.


4) 테마명으로 monokai를 입력한다.


5) .emacs 파일에 아래와 같이 추가한다.


(load-theme 'monokai)





<테스트 환경>

OS : Windows 7

Emacs 버전 : Emacs 24.3 윈도우


,