本文整理汇总了Python中past.model.status.Status.get_max_origin_id方法的典型用法代码示例。如果您正苦于以下问题:Python Status.get_max_origin_id方法的具体用法?Python Status.get_max_origin_id怎么用?Python Status.get_max_origin_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类past.model.status.Status
的用法示例。
在下文中一共展示了Status.get_max_origin_id方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sync
# 需要导入模块: from past.model.status import Status [as 别名]
# 或者: from past.model.status.Status import get_max_origin_id [as 别名]
def sync(t, old=False):
if not t:
print 'no such task'
return 0
log.info("the sync task is :%s" % t)
try:
alias = None
provider = category2provider(t.category)
alias = UserAlias.get_by_user_and_type(t.user_id,
config.OPENID_TYPE_DICT[provider])
if not alias:
log.warn("no alias...")
return 0
token = OAuth2Token.get(alias.id)
if not token:
log.warn("no access token, break...")
return 0
client = None
if provider == config.OPENID_DOUBAN:
client = Douban.get_client(alias.user_id)
elif provider == config.OPENID_SINA:
client = SinaWeibo.get_client(alias.user_id)
elif provider == config.OPENID_TWITTER:
client = TwitterOAuth1.get_client(alias.user_id)
elif provider == config.OPENID_QQ:
client = QQWeibo.get_client(alias.user_id)
elif provider == config.OPENID_RENREN:
client = Renren.get_client(alias.user_id)
elif provider == config.OPENID_INSTAGRAM:
client = Instagram.get_client(alias.user_id)
if not client:
log.warn("get client fail, break...")
return 0
if t.category == config.CATE_DOUBAN_NOTE:
if old:
start = Status.get_count_by_cate(t.category, t.user_id)
else:
start = 0
note_list = client.get_notes(start, 50)
if note_list:
for x in note_list:
Status.add_from_obj(t.user_id, x, json_encode(x.get_data()))
return len(note_list)
elif t.category == config.CATE_DOUBAN_MINIBLOG:
if old:
start = Status.get_count_by_cate(t.category, t.user_id)
else:
start = 0
miniblog_list = client.get_miniblogs(start, 50)
if miniblog_list:
for x in miniblog_list:
Status.add_from_obj(t.user_id, x, json_encode(x.get_data()))
return len(miniblog_list)
elif t.category == config.CATE_DOUBAN_STATUS:
origin_min_id = Status.get_min_origin_id(t.category, t.user_id)
if old:
log.info("will get douban status order than %s..." % origin_min_id)
status_list = client.get_timeline(until_id=origin_min_id)
else:
log.info("will get douban status newer than %s..." % origin_min_id)
status_list = client.get_timeline(since_id=origin_min_id, count=20)
if status_list:
log.info("get douban status succ, len is %s" % len(status_list))
for x in status_list:
Status.add_from_obj(t.user_id, x, json_encode(x.get_data()))
elif t.category == config.CATE_SINA_STATUS:
origin_min_id = Status.get_min_origin_id(t.category, t.user_id) #means the earliest id
origin_max_id = Status.get_max_origin_id(t.category, t.user_id) #meas the latest id
if old:
log.info("will get sinaweibo order than %s..." % origin_min_id)
status_list = client.get_timeline(until_id=origin_min_id)
## 如果根据max_id拿不到数据,那么根据page再fetch一次或者until_id - 1
if status_list and len(status_list) < 20 and origin_min_id is not None:
log.info("again will get sinaweibo order than %s..." % (int(origin_min_id)-1))
status_list = client.get_timeline(until_id=int(origin_min_id)-1)
else:
log.info("will get sinaweibo newer than %s..." % origin_max_id)
status_list = client.get_timeline(since_id=origin_max_id, count=50)
if status_list:
log.info("get sinaweibo succ, len is %s" % len(status_list))
for x in status_list:
Status.add_from_obj(t.user_id, x, json_encode(x.get_data()))
return len(status_list)
elif t.category == config.CATE_TWITTER_STATUS:
origin_min_id = Status.get_min_origin_id(t.category, t.user_id)
origin_max_id = Status.get_max_origin_id(t.category, t.user_id)
if old:
log.info("will get tweets order than %s..." % origin_min_id)
status_list = client.get_timeline(max_id=origin_min_id)
else:
log.info("will get tweets newer than %s..." % origin_max_id)
status_list = client.get_timeline(since_id=origin_max_id, count=50)
if status_list:
log.info("get tweets succ, len is %s" % len(status_list))
for x in status_list:
#.........这里部分代码省略.........