Skip to content

Commit

Permalink
add headimg() func v0.3.5
Browse files Browse the repository at this point in the history
  • Loading branch information
andelf committed Jun 7, 2011
1 parent 3646675 commit cbf131a
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 22 deletions.
15 changes: 15 additions & 0 deletions api.doc.rst
Expand Up @@ -725,6 +725,7 @@ User

* self
是否为自己
* headimg(size=...) 获取头像 URL
* update(\*\*kwargs)
* timeline(\*\*kwargs)
* add() / follow()
Expand Down Expand Up @@ -769,6 +770,11 @@ id 属性可能是各种返回结果的 id, 不一定是 Tweet.
pageflag+pagetime
-----------------

* pageflag: 分页标识(0:第一页,1:向下翻页,2向上翻页)
* pagetime: 本页起始时间(第一页 时填0,继续翻页:填上一次请求返回的最后一条记录时间)

返回中 data/hasnext: 0 表示还有微博可拉取 1 已拉取完毕

::

> api.timeline.home(reqnum=1)
Expand Down Expand Up @@ -859,6 +865,13 @@ twitterid
* 已知 tagid 无法获得 tagtext
* 文档很悲剧的说, 没有及时更新, 不完整
* public_timeline 中翻页参数 pos 无法跟踪大量更新, 基本是废参数
* 根据 REST API 设计准则, 这样的 API 不应该有 HTTP 错误, 告别 500, 400.

* 单元测试结果

* api.timeline.topic 返回 tweet 数一般要比 reqnum 少一些, hasnext 为 True
* contenttype 指定为 8 (带视频)时, 返回 tweet 可能没有 video 信息
* api.timeline.mentions 返回也有可能是被转发, 即, 不存在 @ 引用用户名

------
FAQ
Expand All @@ -868,6 +881,8 @@ FAQ

我还不知道.

由于 Python 2.5 不支持 except ExceptionName as e 的语法. 所以本 SDK 不支持 Python 2.5-. 如有需要, 可以自行修改

-------------
错误代码查询
-------------
Expand Down
9 changes: 5 additions & 4 deletions qqweibo/__init__.py
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-
# Copyright 2011 andelf <andelf@gmail.com>
# See LICENSE for details.
# Time-stamp: <2011-06-05 01:44:27 andelf>
# Time-stamp: <2011-06-06 15:04:03 andelf>

from qqweibo.auth import OAuthHandler
from qqweibo.api import API
Expand All @@ -12,8 +12,9 @@
from qqweibo.cache import MemoryCache, FileCache


__all__ = ['OAuthHandler', 'API', 'ModelParser', 'JSONParser',
__all__ = ['OAuthHandler', 'API', 'QWeiboError', 'version',
'XMLRawParser', 'XMLDomParser', 'XMLETreeParser',
'QWeiboError', 'MemoryCache', 'FileCache', 'version']
'ModelParser', 'JSONParser',
'MemoryCache', 'FileCache']

version = '0.3.4'
version = '0.3.5'
8 changes: 1 addition & 7 deletions qqweibo/binder.py
Expand Up @@ -3,7 +3,7 @@
# Copyright 2009-2010 Joshua Roesslein
# Copyright 2011 andelf <andelf@gmail.com>
# See LICENSE for details.
# Time-stamp: <2011-06-04 11:34:52 andelf>
# Time-stamp: <2011-06-06 15:06:54 andelf>

import time
import re
Expand Down Expand Up @@ -202,11 +202,5 @@ def _call(api, *args, **kargs):
method = APIMethod(api, args, kargs)
return method.execute()

# Set pagination mode
if 'pagetime' in APIMethod.allowed_param:
_call.pagination_mode = 'pagetime'
elif 'page' in APIMethod.allowed_param:
_call.pagination_mode = 'page'

return _call

7 changes: 6 additions & 1 deletion qqweibo/models.py
Expand Up @@ -3,7 +3,7 @@
# Copyright 2009-2010 Joshua Roesslein
# Copyright 2011 andelf <andelf@gmail.com>
# See LICENSE for details.
# Time-stamp: <2011-06-05 01:02:22 andelf>
# Time-stamp: <2011-06-06 16:39:35 andelf>

from qqweibo.utils import (parse_datetime, parse_html_value, parse_a_href,
parse_search_datetime, unescape_html)
Expand Down Expand Up @@ -249,6 +249,11 @@ def pm(self, content, clientip='127.0.0.1', jing=None, wei=None):
assertion(not bool(self.self), "you can't pm yourself")
return self._api.private.add(self.name, content, clientip, jing, wei)

def headimg(self, size=100):
assertion(size in [20, 30, 40, 50, 100],
'size must be one of 20 30 40 50 100')
return '%s/%s' % (self.head, size)


class JSON(Model):

Expand Down
24 changes: 18 additions & 6 deletions qqweibo/parsers.py
Expand Up @@ -3,7 +3,7 @@
# Copyright 2009-2010 Joshua Roesslein
# Copyright 2011 andelf <andelf@gmail.com>
# See LICENSE for details.
# Time-stamp: <2011-06-06 00:46:10 andelf>
# Time-stamp: <2011-06-07 10:31:59 andelf>

import xml.dom.minidom as dom
import xml.etree.ElementTree as ET
Expand Down Expand Up @@ -92,9 +92,15 @@ def parse(self, method, payload):
json = JSONParser.parse(self, method, payload)
data = json['data']

print (dir(method))
print (method.parameters)
print (method.method)
#if data is None and method.payload_type:
# if method.payload_list:
# data = []
# #
# else:
# raise QWeiboError(json.get['msg'])
#print (dir(method))
#print (method.parameters)
#print (method.method)
# pager support
if 'pagetime' in method.allowed_param:
pass
Expand All @@ -104,11 +110,17 @@ def parse(self, method, payload):
# if 'info' in json:
# hasnext = json.get('hasnext', 1) == 0
# json = json['info'] # got data list or data
if 'info' in data:
data = data['info']

if method.payload_list:
# sometimes data will be a None
if data and 'info' in data:
# need pager
hasnext = data['hasnext'] == 0
data = data['info']
else:
hasnext = False
result = model.parse_list(method.api, data)
result.hasnext = hasnext
else:
result = model.parse(method.api, data)
return result
Expand Down
8 changes: 4 additions & 4 deletions setup.py
@@ -1,7 +1,7 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2011 andelf <andelf@gmail.com>
# Time-stamp: <2011-06-05 01:54:24 andelf>
# Time-stamp: <2011-06-06 16:08:30 andelf>

#from distutils.core import setup
from setuptools import setup, find_packages
Expand Down Expand Up @@ -30,9 +30,9 @@
* fix the bad offical api names and arangement.
* With model parser support, cache support.
* Under active development.
* Py2.x and Py3.x support
* document & samples included
* MIT license
* Supports Python 2.6 - 2.7 and 3.1 - 3.2.
* Document & samples included.
* MIT license.
NOTE: this is a thrid party SDK, use at your risk.
""",
Expand Down

0 comments on commit cbf131a

Please sign in to comment.