From cbf131aa84521545f46ed3e285042cb22e605dc4 Mon Sep 17 00:00:00 2001 From: Feather Andelf Date: Tue, 7 Jun 2011 11:22:59 +0800 Subject: [PATCH] add headimg() func v0.3.5 --- api.doc.rst | 15 +++++++++++++++ qqweibo/__init__.py | 9 +++++---- qqweibo/binder.py | 8 +------- qqweibo/models.py | 7 ++++++- qqweibo/parsers.py | 24 ++++++++++++++++++------ setup.py | 8 ++++---- 6 files changed, 49 insertions(+), 22 deletions(-) diff --git a/api.doc.rst b/api.doc.rst index 5ccf58f..7b23c76 100644 --- a/api.doc.rst +++ b/api.doc.rst @@ -725,6 +725,7 @@ User * self 是否为自己 +* headimg(size=...) 获取头像 URL * update(\*\*kwargs) * timeline(\*\*kwargs) * add() / follow() @@ -769,6 +770,11 @@ id 属性可能是各种返回结果的 id, 不一定是 Tweet. pageflag+pagetime ----------------- +* pageflag: 分页标识(0:第一页,1:向下翻页,2向上翻页) +* pagetime: 本页起始时间(第一页 时填0,继续翻页:填上一次请求返回的最后一条记录时间) + +返回中 data/hasnext: 0 表示还有微博可拉取 1 已拉取完毕 + :: > api.timeline.home(reqnum=1) @@ -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 @@ -868,6 +881,8 @@ FAQ 我还不知道. +由于 Python 2.5 不支持 except ExceptionName as e 的语法. 所以本 SDK 不支持 Python 2.5-. 如有需要, 可以自行修改 + ------------- 错误代码查询 ------------- diff --git a/qqweibo/__init__.py b/qqweibo/__init__.py index 942841a..b4b354f 100644 --- a/qqweibo/__init__.py +++ b/qqweibo/__init__.py @@ -2,7 +2,7 @@ # -*- coding: utf-8 -*- # Copyright 2011 andelf # 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 @@ -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' diff --git a/qqweibo/binder.py b/qqweibo/binder.py index 3cb2950..2e7c5b9 100644 --- a/qqweibo/binder.py +++ b/qqweibo/binder.py @@ -3,7 +3,7 @@ # Copyright 2009-2010 Joshua Roesslein # Copyright 2011 andelf # 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 @@ -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 diff --git a/qqweibo/models.py b/qqweibo/models.py index 2f109f7..4a205ef 100644 --- a/qqweibo/models.py +++ b/qqweibo/models.py @@ -3,7 +3,7 @@ # Copyright 2009-2010 Joshua Roesslein # Copyright 2011 andelf # 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) @@ -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): diff --git a/qqweibo/parsers.py b/qqweibo/parsers.py index d67774e..48c321f 100644 --- a/qqweibo/parsers.py +++ b/qqweibo/parsers.py @@ -3,7 +3,7 @@ # Copyright 2009-2010 Joshua Roesslein # Copyright 2011 andelf # 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 @@ -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 @@ -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 diff --git a/setup.py b/setup.py index d3855a7..61e5cc7 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright 2011 andelf -# 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 @@ -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. """,