python 및 머신러닝 교육, 슬로우캠퍼스

웹서버  

tornado server를 웹서버로 사용

mongoDB를 db로 사용

(chat server 는 따로 mongoDB 사용. 서로 분리됨)

tornado sever 사용


서버기동확인 방법:

# ps -ef | grep py



# python chatdemo.py --port=8100


홈피 수정

# /home/tornado_demos/chat/templates/index.html 수정해보기 바람



현재 /tmp/chat/  에서  8000 포트로 기동한 상태.


서버확인:

브라우저에서


http://weechat.kr:8000



twitter 서버 연동 - oauth

oauth 연동 샘플 사이트

Twitter OAuth Demo


이 사이트의 소스

https://github.com/tav/tweetapp


twitter API용 python lib tweepy


# pip install tweepy




OAuth settings

Your application's OAuth settings. Keep the "Consumer secret" a secret. This key should never be human-readable in your application.

Access level

Read-only

About the application permission model

Consumer key

lj1tenUgCtXJUnfmvN7PWA

Consumer secret

DBYk5Qdnew9nnye9JFD5KlI4cCbueunRPzJBo

Request token URL

https://api.twitter.com/oauth/request_token

Authorize URL

https://api.twitter.com/oauth/authorize

Access token URL

https://api.twitter.com/oauth/access_token

Callback URL

http://weechat.kr/twt_oauth_callback

Your access token

Use the access token string as your "oauth_token" and the access token secret as your "oauth_token_secret" to sign requests with your own Twitter account. Do not share youroauth_token_secret with anyone.

Access token

102303698-vdawrDimKPI4w3IGWWse3pnQQym9OA8RftjCd5wx

Access token secret

WZ5Xv7W3hXKBGyqq7BYeQNjDjqq6Op79VnUpvtbLg

Access level

Read-only









oauth동작 과정


http://twitteroauth.appspot.com/oauth/twitter/login  에 접속하면

http://twitter.com/oauth/authorize 로 redirect 됨


# wget -d -o aa -O aaa http://twitteroauth.appspot.com/oauth/twitter/login



--2011-08-07 14:13:59--  http://twitteroauth.appspot.com/oauth/twitter/login

Resolving twitteroauth.appspot.com... 64.233.183.141

Connecting to twitteroauth.appspot.com|64.233.183.141|:80... connected.

HTTP request sent, awaiting response... 302 Found

Location: http://twitter.com/oauth/authorize?oauth_nonce=12747081930362030444&oauth_timestamp=1312694038&oauth_consumer_key=cZy7GCndV0v6xrfVSirG2g&oauth_signature_method=HMAC-SHA1&oauth_version=1.0&oauth_token=bZQppJGeif5Xz3CzUe6HsGrS3Cc2JI33AgdP6PMSI&oauth_signature=moJc6hA9nWl3nl23qd2OyPeOWDY%3D [following]

--2011-08-07 14:14:00--  http://twitter.com/oauth/authorize?oauth_nonce=12747081930362030444&oauth_timestamp=1312694038&oauth_consumer_key=cZy7GCndV0v6xrfVSirG2g&oauth_signature_method=HMAC-SHA1&oauth_version=1.0&oauth_token=bZQppJGeif5Xz3CzUe6HsGrS3Cc2JI33AgdP6PMSI&oauth_signature=moJc6hA9nWl3nl23qd2OyPeOWDY%3D

Resolving twitter.com... 199.59.148.10, 199.59.148.82, 199.59.149.230

Connecting to twitter.com|199.59.148.10|:80... connected.

HTTP request sent, awaiting response... 200 OK

Length: 7585 (7.4K) [text/html]

Saving to: `aaa'


    0K .......                                               100% 42.4K=0.2s


2011-08-07 14:14:00 (42.4 KB/s) - `aaa' saved [7585/7585]








---


GET /twt_oauth_callback?oauth_token=8SCjZmZtbaSyMqnOBqbMAiK5310mmnhXuNMWd2OoYc&oauth_verifier=8X2zECUz9HZqfHLTvaP7MdIpdTCA6uItzGyG9Tu5w (61.43.139.4) 0.74ms




Tweepy

twitter api 사용




<tweepy.models.User object at 0x2b7041979190>

['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getstate__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_api', 'contributors_enabled', 'created_at', 'default_profile', 'default_profile_image', 'description', 'favourites_count', 'follow', 'follow_request_sent', 'followers', 'followers_count', 'followers_ids', 'following', 'friends', 'friends_count', 'geo_enabled', 'id', 'id_str', 'is_translator', 'lang', 'listed_count', 'lists', 'lists_memberships', 'lists_subscriptions', 'location', 'name', 'notifications', 'parse', 'parse_list', 'profile_background_color', 'profile_background_image_url', 'profile_background_image_url_https', 'profile_background_tile', 'profile_image_url', 'profile_image_url_https', 'profile_link_color', 'profile_sidebar_border_color', 'profile_sidebar_fill_color', 'profile_text_color', 'profile_use_background_image', 'protected', 'screen_name', 'show_all_inline_media', 'status', 'statuses_count', 'time_zone', 'timeline', 'unfollow', 'url', 'utc_offset', 'verified']



======= Direct Mesg

['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getstate__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_api', 'created_at', 'destroy', 'id', 'id_str', 'parse', 'parse_list', 'recipient', 'recipient_id', 'recipient_screen_name', 'sender', 'sender_id', 'sender_screen_name', 'text']



======= User Timeline

['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getstate__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_api', 'author', 'contributors', 'coordinates', 'created_at', 'destroy', 'favorite', 'favorited', 'geo', 'id', 'id_str', 'in_reply_to_screen_name', 'in_reply_to_status_id', 'in_reply_to_status_id_str', 'in_reply_to_user_id', 'in_reply_to_user_id_str', 'parse', 'parse_list', 'place', 'retweet', 'retweet_count', 'retweeted', 'retweets', 'source', 'source_url', 'text', 'truncated', 'user']


======= Mentions

16

['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getstate__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_api', 'author', 'contributors', 'coordinates', 'created_at', 'destroy', 'favorite', 'favorited', 'geo', 'id', 'id_str', 'in_reply_to_screen_name', 'in_reply_to_status_id', 'in_reply_to_status_id_str', 'in_reply_to_user_id', 'in_reply_to_user_id_str', 'parse', 'parse_list', 'place', 'retweet', 'retweet_count', 'retweeted', 'retweets', 'source', 'text', 'truncated', 'user']

'Cloud Computing > NoSQL, DB' 카테고리의 다른 글

pymongo, mongoDB, twitter 연동 tweepy  (0) 2013.07.25

WRITTEN BY
manager@
Data Analysis, Text/Knowledge Mining, Python, Cloud Computing, Platform

,