本文整理汇总了Python中past.model.user.UserAlias.gets_by_user_id方法的典型用法代码示例。如果您正苦于以下问题:Python UserAlias.gets_by_user_id方法的具体用法?Python UserAlias.gets_by_user_id怎么用?Python UserAlias.gets_by_user_id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类past.model.user.UserAlias
的用法示例。
在下文中一共展示了UserAlias.gets_by_user_id方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: before_request
# 需要导入模块: from past.model.user import UserAlias [as 别名]
# 或者: from past.model.user.UserAlias import gets_by_user_id [as 别名]
def before_request():
g.user = auth_user_from_session(session)
#g.user = User.get(2)
if g.user:
g.user_alias = UserAlias.gets_by_user_id(g.user.id)
else:
g.user_alias = None
if g.user:
unbinded = list(set(config.OPENID_TYPE_DICT.values()) -
set([ua.type for ua in g.user.get_alias()]) - set([config.OPENID_TYPE_DICT[config.OPENID_THEPAST]]))
tmp = {}
for k, v in config.OPENID_TYPE_DICT.items():
tmp[v] = k
g.unbinded = [[x, tmp[x], config.OPENID_TYPE_NAME_DICT[x]] for x in unbinded]
expired_providers = []
for t in [ua.type for ua in g.user.get_alias()]:
p = g.user.get_thirdparty_profile(t)
if p and p.get("expired"):
_ = [t, config.OPENID_TYPE_DICT_REVERSE.get(t), config.OPENID_TYPE_NAME_DICT.get(t, "")]
expired_providers.append(_)
if expired_providers:
msg = " ".join([x[-1] for x in expired_providers])
flash(u"你的 %s 授权已经过期了,会影响数据同步,你可以重新授权 :)", "tip")
else:
g.unbinded = None
g.start = int(request.args.get('start', 0))
g.count = int(request.args.get('count', 30))
g.cate = request.args.get("cate", "")
if not g.cate.isdigit():
g.cate = ""
示例2: generate
# 需要导入模块: from past.model.user import UserAlias [as 别名]
# 或者: from past.model.user.UserAlias import gets_by_user_id [as 别名]
def generate(user_id, date, order='asc'):
try:
uas = UserAlias.gets_by_user_id(user_id)
if not uas:
return
start_date = datetime.datetime(date.year, date.month, 1)
end_date = datetime.datetime(date.year, date.month,
calendar.monthrange(date.year, date.month)[1], 23, 59, 59)
pdf_filename = get_pdf_filename(user_id, date.strftime("%Y%m"))
print '----generate pdf:', start_date, ' to ', end_date, ' file is', pdf_filename
if is_pdf_file_exists(pdf_filename):
print '---- %s exists, so ignore...' % pdf_filename
return
status_ids = Status.get_ids_by_date(user_id, start_date, end_date)[:900]
if order == 'asc':
status_ids = status_ids[::-1]
if not status_ids:
print '----- status ids is none', status_ids
return
generate_pdf(pdf_filename, user_id, status_ids, capacity=-1)
if not is_pdf_file_exists(pdf_filename):
print '----%s generate pdf for user:%s fail' % (datetime.datetime.now(), user_id)
else:
print '----%s generate pdf for user:%s succ' % (datetime.datetime.now(), user_id)
except Exception, e:
import traceback
print '%s %s' % (datetime.datetime.now(), traceback.format_exc())
示例3: sync_wordpress
# 需要导入模块: from past.model.user import UserAlias [as 别名]
# 或者: from past.model.user.UserAlias import gets_by_user_id [as 别名]
def sync_wordpress(t, refresh=False):
if not t:
log.warning('no_wordpress_sync_task')
return
#一个人可以有多个wordpress的rss源地址
rs = UserAlias.gets_by_user_id(t.user_id)
uas = []
for x in rs:
if x.type == config.OPENID_TYPE_DICT[config.OPENID_WORDPRESS]:
uas.append(x)
if not uas:
log.warning('no_wordpress_alias')
return
for ua in uas:
try:
client = Wordpress(ua.alias)
rs = client.get_feeds(refresh)
if rs:
log.info("get wordpress succ, result length is:%s" % len(rs))
for x in rs:
Status.add_from_obj(t.user_id, x, json_encode(x.get_data()))
return
except:
import traceback; print traceback.format_exc()
示例4: before_request
# 需要导入模块: from past.model.user import UserAlias [as 别名]
# 或者: from past.model.user.UserAlias import gets_by_user_id [as 别名]
def before_request():
g.user = auth_user_from_session(session)
if g.user:
g.user_alias = UserAlias.gets_by_user_id(g.user.id)
else:
g.user_alias = None
g.start = int(request.args.get("start", 0))
g.count = int(request.args.get("count", 30))
g.cate = request.args.get("cate", None)
示例5: before_request
# 需要导入模块: from past.model.user import UserAlias [as 别名]
# 或者: from past.model.user.UserAlias import gets_by_user_id [as 别名]
def before_request():
g.config = config
g.user = auth_user_from_session(session)
#g.user = User.get(2)
g.user_alias = UserAlias.gets_by_user_id(g.user.id) if g.user else None
if request.method == 'POST':
try:
g.start = int(request.form.get('start', 0))
except ValueError:
g.start = 0
try:
g.count = int(request.form.get('count', 24))
except ValueError:
g.count = 0
g.cate = request.form.get("cate", "")
else:
try:
g.start = int(request.args.get('start', 0))
except ValueError:
g.start = 0
try:
g.count = int(request.args.get('count', 24))
except ValueError:
g.count = 0
g.cate = request.args.get("cate", "")
g.cate = int(g.cate) if g.cate.isdigit() else ""
if g.user:
g.binds = [ua.type for ua in g.user.get_alias()]
unbinded = list(set(config.OPENID_TYPE_DICT.values()) -
set(g.binds) - set([config.OPENID_TYPE_DICT[config.OPENID_THEPAST]]))
tmp = {}
for k, v in config.OPENID_TYPE_DICT.items():
tmp[v] = k
g.unbinded = [[x, tmp[x], config.OPENID_TYPE_NAME_DICT[x]] for x in unbinded]
expired_providers = []
for t in [ua.type for ua in g.user.get_alias()]:
p = g.user.get_thirdparty_profile(t)
if p and p.get("expired"):
_ = [t, config.OPENID_TYPE_DICT_REVERSE.get(t), config.OPENID_TYPE_NAME_DICT.get(t, "")]
expired_providers.append(_)
g.expired = expired_providers
if expired_providers:
msg = " ".join([x[-1] for x in expired_providers])
flash(u"你的 %s 授权已经过期了,会影响数据同步,你可以重新授权 :)" % msg, "tip")
else:
g.unbinded = None
示例6: before_request
# 需要导入模块: from past.model.user import UserAlias [as 别名]
# 或者: from past.model.user.UserAlias import gets_by_user_id [as 别名]
def before_request():
g.user = auth_user_from_session(session)
if g.user:
g.user_alias = UserAlias.gets_by_user_id(g.user.id)
else:
g.user_alias = None
if g.user:
unbinded = list(set(config.OPENID_TYPE_DICT.values()) - set([ua.type for ua in g.user.get_alias()]))
tmp = {}
for k, v in config.OPENID_TYPE_DICT.items():
tmp[v] = k
g.unbinded = [[x, tmp[x], config.OPENID_TYPE_NAME_DICT[x]] for x in unbinded]
else:
g.unbinded = None
g.start = int(request.args.get("start", 0))
g.count = int(request.args.get("count", 30))
g.cate = request.args.get("cate", None)
示例7: sync
# 需要导入模块: from past.model.user import UserAlias [as 别名]
# 或者: from past.model.user.UserAlias import gets_by_user_id [as 别名]
def sync(cates):
cates = cates.split("|")
if not (cates and isinstance(cates, list)):
return "no cates"
cates = filter(lambda x: x in [str(y) for y in config.CATE_LIST], cates)
if not cates:
abort(400, "not support such cates")
provider = category2provider(int(cates[0]))
redir = "/connect/%s" % provider
if not g.user:
print '--- no g.user...'
return redirect(redir)
if request.form.get("remove"):
for c in cates:
r = SyncTask.gets_by_user_and_cate(g.user, str(c))
for x in r:
x.remove()
return json_encode({'ok':'true'})
uas = UserAlias.gets_by_user_id(g.user.id)
r = filter(lambda x: x.type == config.OPENID_TYPE_DICT[provider], uas)
user_alias = r and r[0]
if not user_alias:
print '--- no user_alias...'
return json_encode({'ok':'false', 'redir':redir})
token = OAuth2Token.get(user_alias.id)
if not token:
print '--- no token...'
return json_encode({'ok':'false', 'redir':redir})
for c in cates:
SyncTask.add(c, g.user.id)
return json_encode({'ok':'true'})
示例8: execfile
# 需要导入模块: from past.model.user import UserAlias [as 别名]
# 或者: from past.model.user.UserAlias import gets_by_user_id [as 别名]
import time
import datetime
activate_this = '../env/bin/activate_this.py'
execfile(activate_this, dict(__file__=activate_this))
from past.utils.pdf import generate_pdf, get_pdf_filename, is_pdf_file_exists
from past.model.user import User, UserAlias
from past import config
if __name__ == "__main__":
#for uid in User.get_ids(0, 10000000):
for uid in range(634,652):
try:
uas = UserAlias.gets_by_user_id(uid)
if not uas:
continue
types = [x.type for x in uas]
count = 300
if config.OPENID_TYPE_DICT[config.OPENID_SINA] in types \
or config.OPENID_TYPE_DICT[config.OPENID_QQ] in types:
count = 250
pdf_filename = get_pdf_filename(uid)
print pdf_filename
generate_pdf(pdf_filename, uid, 0, count, capacity=-1)
if not is_pdf_file_exists(pdf_filename):
print '%s generate pdf for user:%s fail' % (datetime.datetime.now(), uid)
else:
print '%s generate pdf for user:%s succ' % (datetime.datetime.now(), uid)
except Exception, e: