Permalink
Browse files

add mit license file

  • Loading branch information...
1 parent 88cf417 commit 0b1d48953408d7ba77467a912681957a01f74351 @andelf committed Apr 8, 2011
Showing with 161 additions and 84 deletions.
  1. +20 −0 LICENSE
  2. +20 −0 LICENSE.tweepy
  3. +8 −8 example.py
  4. +30 −31 qqweibo/api.py
  5. +7 −7 qqweibo/auth.py
  6. +8 −8 qqweibo/binder.py
  7. +67 −29 qqweibo/models.py
  8. +1 −1 qqweibo/utils.py
View
20 LICENSE
@@ -0,0 +1,20 @@
+MIT License
+Copyright (c) 2011 andelf <andelf@gmail.com>
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
View
@@ -0,0 +1,20 @@
+MIT License
+Copyright (c) 2009-2010 Joshua Roesslein
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
View
@@ -1,11 +1,11 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-# FileName : example.py
-# Author : Feather.et.ELF <andelf@139.com>
-# Created : Mon Apr 04 01:12:20 2011 by Feather.et.ELF
-# Copyright : Feather Workshop (c) 2011
-# Description : A example file
-# Time-stamp: <2011-04-07 13:31:59 andelf>
+# FileName : example.py
+# Author : Feather.et.ELF <andelf@139.com>
+# Created : Mon Apr 04 01:12:20 2011 by Feather.et.ELF
+# Copyright : Feather Workshop (c) 2011
+# Description : A example file
+# Time-stamp: <2011-04-08 10:43:28 andelf>
import sys
@@ -100,7 +100,7 @@ def dumpMsg(msgs):
print api.info()
# TEST: unkown, bad, must use all parameter
-#print api.update(introduction=u'just a test')
+#print api.update(introduction=u'just a test')
# TEST: ok
#print api.update_head(ur'C:\Documents and Settings\Administrator\My Documents\My Pictures\me\无标题3453.JPG')
@@ -166,7 +166,7 @@ def dumpMsg(msgs):
print '-'* 20
# TEST: fail, access rate limit
-#print api.userbytag(u'python', 15)
+#print api.userbytag(u'python', 15)
#print api.ht()
View
@@ -160,21 +160,21 @@ def add_pic(self, filename, content, clientip, jing=None, wei=None):
headers, post_data = API._pack_image(filename, 1024, content=content, clientip=clientip, jing=jing, wei=wei, contentname="pic")
args = [content, clientip]
allowed_param = ['content', 'clientip']
-
+
if jing is not None:
args.append(jing)
allowed_param.append('jing')
-
+
if wei is not None:
args.append(wei)
allowed_param.append('wei')
-
+
return bind_api(
path = '/api/t/add_pic',
method = 'POST',
payload_type = 'json',
require_auth = True,
- allowed_param = allowed_param
+ allowed_param = allowed_param
)(self, *args, post_data=post_data, headers=headers)
""" 7.t/re_count 转播数或点评数 """ # FIXME
@@ -224,7 +224,7 @@ def add_pic(self, filename, content, clientip, jing=None, wei=None):
'url'], # supports: youku,tudou,ku6
require_auth = True
)
-
+
""" 12.t/getvideoinfo 获取视频信息 """
getvideoinfo = bind_api(
path = '/api/t/getvideoinfo',
@@ -258,12 +258,12 @@ def update_head(self, filename):
headers, post_data = API._pack_image(filename, 1024, contentname="pic")
args = []
allowed_param = []
-
+
return bind_api(
path = '/api/user/update_head',
method = 'POST',
require_auth = True,
- allowed_param = allowed_param
+ allowed_param = allowed_param
)(self, *args, post_data=post_data, headers=headers)
""" 4.user/other_info 获取其他人资料 """
@@ -297,15 +297,15 @@ def update_head(self, filename):
payload_type = 'user', payload_list = True,
allowed_param = ['reqnum', 'startindex'],
require_auth = True
- )
+ )
""" 4.Friends/speciallist 特别收听列表 """
speciallist = bind_api(
path = '/api/friends/speciallist',
payload_type = 'user', payload_list = True,
allowed_param = ['reqnum', 'startindex'],
require_auth = True
- )
+ )
""" 5.friends/add 收听某个用户 """
@@ -315,7 +315,7 @@ def update_head(self, filename):
method = 'POST',
allowed_param = ['name'],
require_auth = True
- )
+ )
""" 6.friends/del取消收听某个用户 """
# TODO: fix confilicts with add message
@@ -324,48 +324,47 @@ def update_head(self, filename):
method = 'POST',
allowed_param = ['name'],
require_auth = True
- )
+ )
""" 7.friends/addspecial 特别收听某个用户 """
addspecial = bind_api(
path = '/api/friends/addspecial',
method = 'POST',
allowed_param = ['name'],
require_auth = True
- )
+ )
""" 8.friends/delspecial 取消特别收听某个用户 """
delspecial = bind_api(
path = '/api/friends/delspecial',
method = 'POST',
allowed_param = ['name'],
require_auth = True
- )
+ )
""" 9.friends/addblacklist 添加某个用户到黑名单 """
addblacklist = bind_api(
path = '/api/friends/addblacklist',
method = 'POST',
allowed_param = ['name'],
require_auth = True
- )
+ )
""" 10.friends/delblacklist 从黑名单中删除某个用户 """
delblacklist = bind_api(
path = '/api/friends/delblacklist',
method = 'POST',
allowed_param = ['name'],
require_auth = True
- )
-
+ )
""" 11.friends/check 检测是否我的听众或收听的人 """
check = bind_api(
path = '/api/friends/check',
payload_type = 'tweet', payload_list = True,
allowed_param = ['names', 'flag'],
require_auth = True
- )
+ )
""" 12.friends/user_fanslist 其他帐户听众列表 """
user_fanslist = bind_api(
@@ -389,15 +388,15 @@ def update_head(self, filename):
payload_type = 'user', payload_list = True,
allowed_param = ['name', 'reqnum', 'startindex'],
require_auth = True
- )
+ )
- ## 私信相关 ""
+ ## 私信相关 ##
""" 1.private/add 发私信 """
padd = bind_api(
path = '/api/private/add',
method = 'POST',
- payload_type = 'tweet', payload_list = True,
+ payload_type = 'json',
allowed_param = ['content', 'clientip', 'jing',
'wei', 'name'],
require_auth = True
@@ -407,7 +406,7 @@ def update_head(self, filename):
pdel = bind_api(
path = '/api/private/del',
method = 'POST',
- payload_type = 'tweet', payload_list = True,
+ payload_type = 'json',
allowed_param = ['id'],
require_auth = True
)
@@ -416,8 +415,7 @@ def update_head(self, filename):
recv = bind_api(
path = '/api/private/recv',
payload_type = 'tweet', payload_list = True,
- allowed_param = ['pageflag', 'pagetime', 'reqnum',
- 'lastid'],
+ allowed_param = ['pageflag', 'pagetime', 'reqnum', 'lastid'],
require_auth = True
)
@@ -434,7 +432,7 @@ def update_head(self, filename):
""" 1.Search/user 搜索用户 """
user = bind_api(
path = '/api/search/user',
- payload_type = 'tweet', payload_list = True,
+ payload_type = 'user', payload_list = True,
allowed_param = ['keyword', 'pagesize', 'page'],
require_auth = True
)
@@ -450,11 +448,12 @@ def update_head(self, filename):
""" 3.Search/userbytag 通过标签搜索用户 """
userbytag = bind_api(
path = '/api/search/userbytag',
- payload_type = 'tweet', payload_list = True,
+ payload_type = 'user', payload_list = True,
allowed_param = ['keyword', 'pagesize', 'page'],
require_auth = True
)
+ # TODO: model parser
## 热度,趋势 ##
""" 1.trends/ht 话题热榜 """
ht = bind_api(
@@ -577,7 +576,7 @@ def update_head(self, filename):
####################
-
+
""" Get the authenticated user """
def me(self):
return self.get_user(screen_name=self.auth.get_username())
@@ -607,7 +606,7 @@ def _pack_image(filename, max_size, content=None, clientip=None, jing=None, wei=
fp = open(filename, 'rb')
BOUNDARY = 'QqWeIbObYaNdElF'
body = []
- if content is not None:
+ if content is not None:
body.append('--' + BOUNDARY)
body.append('Content-Disposition: form-data; name="content"')
body.append('Content-Type: text/plain; charset=UTF-8')
@@ -616,21 +615,21 @@ def _pack_image(filename, max_size, content=None, clientip=None, jing=None, wei=
if isinstance(content, unicode):
content = content.encode('utf-8')
body.append(content)
- if clientip is not None:
+ if clientip is not None:
body.append('--' + BOUNDARY)
body.append('Content-Disposition: form-data; name="clientip"')
body.append('Content-Type: text/plain; charset=US-ASCII')
body.append('Content-Transfer-Encoding: 8bit')
body.append('')
body.append(clientip)
- if jing is not None:
+ if jing is not None:
body.append('--' + BOUNDARY)
body.append('Content-Disposition: form-data; name="jing"')
body.append('Content-Type: text/plain; charset=US-ASCII')
body.append('Content-Transfer-Encoding: 8bit')
body.append('')
body.append(jing)
- if wei is not None:
+ if wei is not None:
body.append('--' + BOUNDARY)
body.append('Content-Disposition: form-data; name="wei"')
body.append('Content-Type: text/plain; charset=US-ASCII')
@@ -645,7 +644,7 @@ def _pack_image(filename, max_size, content=None, clientip=None, jing=None, wei=
body.append(fp.read())
body.append('--' + BOUNDARY + '--')
body.append('')
- fp.close()
+ fp.close()
body.append('--' + BOUNDARY + '--')
body.append('')
body = '\r\n'.join(body)
View
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2009-2010 Joshua Roesslein
-# Copyright 2010 andelf<andelf@gmail.com>
+# Copyright 2010 andelf <andelf@gmail.com>
# See LICENSE for details.
from urllib2 import Request, urlopen
@@ -37,7 +37,7 @@ def __init__(self, username, password):
def apply_auth(self, url, method, headers, parameters):
headers['Authorization'] = 'Basic %s' % self._b64up
-
+
def get_username(self):
return self.username
@@ -132,20 +132,20 @@ def get_access_token(self, verifier=None):
)
request.sign_request(self._sigmethod, self._consumer, self.request_token)
- # send request
+ # send request
resp = urlopen(Request(request.to_url())) # must
self.access_token = oauth.OAuthToken.from_string(resp.read())
-
+
print 'Access token key: '+ str(self.access_token.key)
print 'Access token secret: '+ str(self.access_token.secret)
-
+
return self.access_token
except Exception, e:
raise WeibopError(e)
-
+
def setToken(self, token, tokenSecret):
self.access_token = oauth.OAuthToken(token, tokenSecret)
-
+
def get_username(self):
if self.username is None:
api = API(self)
Oops, something went wrong.

0 comments on commit 0b1d489

Please sign in to comment.