本文整理汇总了Python中past.model.status.Status.get_oldest_create_time方法的典型用法代码示例。如果您正苦于以下问题:Python Status.get_oldest_create_time方法的具体用法?Python Status.get_oldest_create_time怎么用?Python Status.get_oldest_create_time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类past.model.status.Status
的用法示例。
在下文中一共展示了Status.get_oldest_create_time方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pdf
# 需要导入模块: from past.model.status import Status [as 别名]
# 或者: from past.model.status.Status import get_oldest_create_time [as 别名]
def pdf(uid):
user = User.get(uid)
if not user:
abort(404, "No such user")
if uid != g.user.id and user.get_profile_item('user_privacy') == consts.USER_PRIVACY_PRIVATE:
flash(u"由于该用户设置了仅自己可见的权限,所以,我们就看不到了", "tip")
return redirect(url_for("timeline"))
intros = [g.user.get_thirdparty_profile(x).get("intro") for x in config.OPENID_TYPE_DICT.values()]
intros = filter(None, intros)
pdf_files = []
start_date = Status.get_oldest_create_time(None, user.id)
now = datetime.now()
d = start_date
while d and d <= now:
pdf_filename = get_pdf_filename(user.id, d.strftime("%Y%m"))
if is_pdf_file_exists(pdf_filename):
full_file_name = get_pdf_full_filename(pdf_filename)
pdf_files.append([d, pdf_filename, sizeof_fmt(os.path.getsize(full_file_name))])
days = calendar.monthrange(d.year, d.month)[1]
d += timedelta(days=days)
d = datetime(d.year, d.month, 1)
files_dict = defaultdict(list)
for date, filename, filesize in pdf_files:
files_dict[date.year].append([date, filename, filesize])
pdf_applyed = PdfSettings.is_user_id_exists(g.user.id)
return render_template("pdf.html", **locals())
示例2: generate_pdf_by_user
# 需要导入模块: from past.model.status import Status [as 别名]
# 或者: from past.model.status.Status import get_oldest_create_time [as 别名]
def generate_pdf_by_user(user_id):
user = User.get(user_id)
if not user:
return
#XXX:暂时只生成2012年的(uid从98开始的用户)
#XXX:暂时只生成2012年3月份的(uid从166开始的用户)
start_date = Status.get_oldest_create_time(None, user_id)
#start_date = datetime.datetime(2012, 3, 1, 0, 0, 0)
if not start_date:
return
now = datetime.datetime.now()
now = datetime.datetime(now.year, now.month, now.day) - datetime.timedelta(days = calendar.monthrange(now.year, now.month)[1])
d = start_date
while d <= now:
generate(user_id, d)
days = calendar.monthrange(d.year, d.month)[1]
d += datetime.timedelta(days=days)
d = datetime.datetime(d.year, d.month, 1)
示例3: sync
# 需要导入模块: from past.model.status import Status [as 别名]
# 或者: from past.model.status.Status import get_oldest_create_time [as 别名]
def sync(t, old=False):
alias = None
provider = category2provider(t.category)
if provider == config.OPENID_DOUBAN:
alias = UserAlias.get_by_user_and_type(t.user_id,
config.OPENID_TYPE_DICT[config.OPENID_DOUBAN])
elif provider == config.OPENID_SINA:
alias = UserAlias.get_by_user_and_type(t.user_id,
config.OPENID_TYPE_DICT[config.OPENID_SINA])
elif provider == config.OPENID_TWITTER:
alias = UserAlias.get_by_user_and_type(t.user_id,
config.OPENID_TYPE_DICT[config.OPENID_TWITTER])
elif provider == config.OPENID_QQ:
alias = UserAlias.get_by_user_and_type(t.user_id,
config.OPENID_TYPE_DICT[config.OPENID_QQ])
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(alias.alias, token.access_token, token.refresh_token)
elif provider == config.OPENID_SINA:
client = SinaWeibo(alias.alias, token.access_token)
elif provider == config.OPENID_TWITTER:
client = Twitter(alias.alias)
elif provider == config.OPENID_QQ:
client = QQWeibo(alias.alias)
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 or t.category == config.CATE_SINA_STATUS:
if old:
until_id = Status.get_min_origin_id(t.category, t.user_id) #means max_id
status_list = client.get_timeline(until_id=until_id)
else:
since_id = Status.get_min_origin_id(t.category, t.user_id)
status_list = client.get_timeline(since_id=since_id)
if 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:
if old:
until_id = Status.get_min_origin_id(t.category, t.user_id) #means max_id
status_list = client.get_timeline(max_id=until_id)
else:
since_id = Status.get_min_origin_id(t.category, t.user_id)
status_list = client.get_timeline(since_id=since_id)
if 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_QQWEIBO_STATUS:
if old:
oldest_create_time = Status.get_oldest_create_time(t.category, t.user_id)
oldest_create_time = datetime2timestamp(oldest_create_time)
status_list = client.get_old_timeline(oldest_create_time, reqnum=200)
else:
status_list = client.get_new_timeline(reqnum=20)
if status_list:
for x in status_list:
Status.add_from_obj(t.user_id, x, json_encode(x.get_data()))
return len(status_list)
return 0
示例4: sync
# 需要导入模块: from past.model.status import Status [as 别名]
# 或者: from past.model.status.Status import get_oldest_create_time [as 别名]
#.........这里部分代码省略.........
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(alias.alias, token.access_token, token.refresh_token)
elif provider == config.OPENID_SINA:
client = SinaWeibo(alias.alias, token.access_token)
elif provider == config.OPENID_TWITTER:
client = Twitter(alias.alias)
elif provider == config.OPENID_QQ:
client = QQWeibo(alias.alias)
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 max_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再拿一次
if len(status_list) <= 1:
downloaded_status_count = Status.get_count_by_user(t.user_id)
page = downloaded_status_count / 100 + 2
status_list = client.get_timeline_by_page(page=page)
else:
log.info("will get sinaweibo newer than %s..." % origin_min_id)
status_list = client.get_timeline(since_id=origin_min_id, count=20)
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)
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_min_id)
status_list = client.get_timeline(since_id=origin_min_id, count=20)
if status_list:
log.info("get tweets 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_QQWEIBO_STATUS:
if old:
oldest_create_time = Status.get_oldest_create_time(t.category, t.user_id)
log.info("will get qqweibo order than %s" % oldest_create_time)
if oldest_create_time is not None:
oldest_create_time = datetime2timestamp(oldest_create_time)
status_list = client.get_old_timeline(oldest_create_time, reqnum=200)
else:
log.info("will get qqweibo new timeline")
status_list = client.get_new_timeline(reqnum=20)
if status_list:
log.info("get qqweibo succ, result length 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)
except:
import traceback; print traceback.format_exc()
return 0
示例5: sync
# 需要导入模块: from past.model.status import Status [as 别名]
# 或者: from past.model.status.Status import get_oldest_create_time [as 别名]
#.........这里部分代码省略.........
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:
Status.add_from_obj(t.user_id, x, json_encode(x.get_data()))
return len(status_list)
elif t.category == config.CATE_QQWEIBO_STATUS:
if old:
oldest_create_time = Status.get_oldest_create_time(t.category, t.user_id)
log.info("will get qqweibo order than %s" % oldest_create_time)
if oldest_create_time is not None:
oldest_create_time = datetime2timestamp(oldest_create_time)
status_list = client.get_old_timeline(oldest_create_time, reqnum=200)
else:
log.info("will get qqweibo new timeline")
status_list = client.get_new_timeline(reqnum=20)
if status_list:
log.info("get qqweibo succ, result length 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_RENREN_STATUS:
if old:
count = 100
total_count = Status.get_count_by_cate(t.category, t.user_id)
page = int(total_count / count) + 1
log.info("will get older renren status, page=%s, count=%s" %(page, count))
status_list = client.get_timeline(page, count)
else:
count = 20
page = 1
log.info("will get newest renren status, page=%s, count=%s" %(page, count))
status_list = client.get_timeline(page, count)
if status_list:
log.info("get renren status succ, result length 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_RENREN_BLOG:
if old:
count = 50