本文整理汇总了Python中past.model.status.Status类的典型用法代码示例。如果您正苦于以下问题:Python Status类的具体用法?Python Status怎么用?Python Status使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Status类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send_today_in_history
def send_today_in_history(user_id):
u = User.get(user_id)
if not u:
return
setting = u.get_profile_item("email_remind_today_in_history")
if setting == 'N':
print '---user %s does not like to receive remind mail' % u.id
return
email = u.get_email()
if not email:
print '---- user %s no email' % u.id
return
yesterday_ids = get_status_ids_yesterday(u.id,
day=(datetime.datetime.now() - datetime.timedelta(days=1)).strftime("%Y-%m-%d"))
status_of_yesterday = Status.gets(yesterday_ids)
history_ids = get_status_ids_today_in_history(u.id,
day=datetime.datetime.now().strftime("%Y-%m-%d"))
status_of_today_in_history = Status.gets(history_ids)
intros = [u.get_thirdparty_profile(x).get("intro") for x in config.OPENID_TYPE_DICT.values()]
intros = filter(None, intros)
history_ids = get_status_ids_today_in_history(u.id,
day=datetime.datetime.now().strftime("%Y-%m-%d"))
d = {}
for s in Status.gets(history_ids):
t = s.create_time.strftime("%Y-%m-%d")
if d.has_key(t):
d[t].append(s)
else:
d[t] = [s]
status_of_today_in_history = d
from past.consts import YESTERDAY
if not (status_of_yesterday or status_of_today_in_history):
print '--- user %s has no status in history' % u.id
return
from jinja2 import Environment, PackageLoader
env = Environment(loader=PackageLoader('past', 'templates'))
env.filters['wrap_long_line'] = wrap_long_line
env.filters['nl2br'] = filters.nl2br
env.filters['clear_html_element'] = clear_html_element
t = env.get_template('mail.html')
m = t.module
html = m.status_in_past(status_of_yesterday, status_of_today_in_history, YESTERDAY, config, intros)
html = html.encode("utf8")
subject = '''来自thepast.me的提醒 %s''' % datetime.datetime.now().strftime("%Y-%m-%d")
text = ''
print '--- send reminding to %s %s' %(user_id, email)
send_mail(["%s" % email], "Today of The Past<[email protected]>", subject, text, html, files=[], server="localhost")
示例2: home
def home():
user_ids = User.get_ids(limit=10000)
user = None
i = 0
while i <= 3:
random_uid = random.choice(user_ids)
user = User.get(random_uid)
r = check_access_user(user)
if not r:
break
i+=1
if user:
history_ids = Status.get_ids(user.id, start=0, limit=20)
status_list = Status.gets(history_ids)
status_list = statuses_timelize(status_list)
intros = [user.get_thirdparty_profile(x).get("intro") for x in config.OPENID_TYPE_DICT.values()]
intros = filter(None, intros)
else:
status_list = []
intros = []
if g.user:
sync_list = get_sync_list(g.user)
else:
sync_list = []
d = defaultdict(list)
for x in status_list:
t = x.create_time.strftime("%Y年%m月%d日")
d[t].append(x)
history_status = d
return render_template("v2/explore.html", **locals())
示例3: remove_user
def remove_user(uid, clear_status=True):
user = User.get(uid)
if not user:
print "---no user:%s" % uid
suicide_log.info("---- delete from user, uid=%s" % uid)
db_conn.execute("delete from user where id=%s", uid)
db_conn.commit()
User._clear_cache(uid)
if clear_status:
cursor = db_conn.execute("select id from status where user_id=%s", uid)
if cursor:
rows = cursor.fetchall()
for row in rows:
sid = row[0]
suicide_log.info("---- delete status text, sid=%s" % sid)
RawStatus.remove(sid)
suicide_log.info("---- delete from status, uid=" % uid)
db_conn.execute("delete from status where user_id=%s", uid)
db_conn.commit()
Status._clear_cache(uid, None)
suicide_log.info("---- delete from passwd, uid=%s" % uid)
db_conn.execute("delete from passwd where user_id=%s", uid)
suicide_log.info("---- delete from sync_task, uid=%s" % uid)
db_conn.execute("delete from sync_task where user_id=%s", uid)
suicide_log.info("---- delete from user_alias, uid=%s" % uid)
db_conn.execute("delete from user_alias where user_id=%s", uid)
db_conn.commit()
示例4: generate_pdf
def generate_pdf(filename, uid, start, count, cate=None, with_head=True, capacity=50*1024):
#########Set FONT################
from xhtml2pdf.default import DEFAULT_FONT
from xhtml2pdf.document import pisaDocument
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfbase.ttfonts import TTFont
pdfmetrics.registerFont(TTFont('zhfont', os.path.join(app.root_path, 'static/font/yahei-consolas.ttf')))
DEFAULT_FONT["helvetica"] = "zhfont"
css = open(os.path.join(app.root_path, "static/css/pdf.css")).read()
#result = StringIO.StringIO()
full_file_name = get_pdf_full_filename(filename)
if not full_file_name:
return None
result = open(full_file_name, 'wb', 1024*1000)
user = User.get(uid)
if not user:
return None
# get status
ids = Status.get_ids(user_id=uid, start=start, limit=count, cate=cate)
status_list = Status.gets(ids)
_html = render(user, status_list, with_head)
_pdf = pisaDocument(_html, result, default_css=css, link_callback=link_callback, capacity=capacity)
result.close()
if not _pdf.err:
return full_file_name
else:
return None
示例5: user_more_by_domain
def user_more_by_domain(uid):
u = User.get(uid)
if not u:
abort(404, "no such user")
r = check_access_user(u)
if r:
abort(400, "no priv to access")
ids = Status.get_ids(user_id=u.id, start=g.start, limit=g.count, cate=g.cate)
status_list = Status.gets(ids)
if g.user and g.user.id == uid:
pass
elif g.user and g.user.id != uid:
status_list = [x for x in status_list if x.privacy() != consts.STATUS_PRIVACY_PRIVATE]
elif not g.user:
status_list = [x for x in status_list if x.privacy() == consts.STATUS_PRIVACY_PUBLIC]
status_list = statuses_timelize(status_list)
intros = [u.get_thirdparty_profile(x).get("intro") for x in config.OPENID_TYPE_DICT.values()]
intros = filter(None, intros)
if g.user:
sync_list = get_sync_list(g.user)
else:
sync_list = []
now = datetime.datetime.now().strftime("%Y年%m月%d日 %H:%M:%S")
return render_template("v2/user_more.html", user=u, intros=intros,
status_list=status_list, config=config, sync_list=sync_list,
now = now)
示例6: index
def index():
if not g.user:
return redirect(url_for("user_explore"))
ids = Status.get_ids(user_id=g.user.id, start=g.start, limit=g.count, cate=g.cate)
status_list = Status.gets(ids)
return render_template("timeline.html", user=g.user, status_list=status_list, config=config)
示例7: user
def user(uid):
u = User.get(uid)
if not u:
abort(404, "no such user")
if g.user and g.user.id == u.id:
return redirect(url_for("timeline"))
if u.get_profile_item('user_privacy') == consts.USER_PRIVACY_PRIVATE:
flash(u"由于该用户设置了仅自己可见的权限,所以,我们就看不到了", "tip")
return redirect(url_for("timeline"))
#TODO:增加可否查看其他用户的权限检查
cate = request.args.get("cate", None)
ids = Status.get_ids(user_id=u.id, start=g.start, limit=g.count, cate=g.cate)
status_list = Status.gets(ids)
status_list = statuses_timelize(status_list)
if status_list:
##XXX:暂时去除了个人关键字的功能
#tags_list = [x[0] for x in get_keywords(u.id, 30)]
tags_list = []
else:
tags_list = []
intros = [u.get_thirdparty_profile(x).get("intro") for x in config.OPENID_TYPE_DICT.values()]
intros = filter(None, intros)
return render_template("timeline.html", user=u, unbinded=[],
tags_list=tags_list, intros=intros, status_list=status_list, config=config)
示例8: remove_user
def remove_user(uid):
user = User.get(uid)
if not user:
print '---no user:%s' % uid
print "---- delete from user, uid=", uid
db_conn.execute("delete from user where id=%s", uid)
db_conn.commit()
User._clear_cache(uid)
cursor = db_conn.execute("select id from status where user_id=%s", uid)
if cursor:
rows = cursor.fetchall()
for row in rows:
sid = row[0]
print "---- delete mongo text, sid=", sid
RawStatus.remove(sid)
print "---- delete from status, uid=", uid
db_conn.execute("delete from status where user_id=%s", uid)
db_conn.commit()
Status._clear_cache(uid, None)
print "---- delete from passwd, uid=", uid
db_conn.execute("delete from passwd where user_id=%s", uid)
print "---- delete from sync_task, uid=", uid
db_conn.execute("delete from sync_task where user_id=%s", uid)
print "---- delete from user_alias, uid=", uid
db_conn.execute("delete from user_alias where user_id=%s", uid)
db_conn.commit()
示例9: sync_wordpress
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()
示例10: user_by_domain
def user_by_domain(uid):
u = User.get(uid)
if not u:
abort(404, "no such user")
r = check_access_user(u)
if r:
flash(r[1].decode("utf8"), "tip")
return redirect(url_for("home"))
ids = Status.get_ids(user_id=u.id, start=g.start, limit=g.count, cate=g.cate)
status_list = Status.gets(ids)
if g.user and g.user.id == uid:
pass
elif g.user and g.user.id != uid:
status_list = [x for x in status_list if x.privacy() != consts.STATUS_PRIVACY_PRIVATE]
elif not g.user:
status_list = [x for x in status_list if x.privacy() == consts.STATUS_PRIVACY_PUBLIC]
status_list = statuses_timelize(status_list)
tags_list = []
intros = [u.get_thirdparty_profile(x).get("intro") for x in config.OPENID_TYPE_DICT.values()]
intros = filter(None, intros)
if g.user:
sync_list = get_sync_list(g.user)
else:
sync_list = []
return render_template("timeline.html", user=u, unbinded=[],
tags_list=tags_list, intros=intros,
status_list=status_list, config=config, sync_list=sync_list)
示例11: render
def render(user, status_list, with_head=True):
if not status_list:
return
date = status_list[0].create_time.strftime("%Y年%m月")
date = date.decode("utf8")
if with_head:
_html = u"""<html> <body>
<div id="Top">
<img src="%s"/> The Past of Me | 个人杂志计划 %s CopyRight©%s
<br/>
</div>
<br/> <br/>
<div class="box">
""" % (os.path.join(app.root_path, "static/img/logo.png"),
date, user.name)
else:
_html = u"""<html> <body><div class="box">"""
from jinja2 import Environment, PackageLoader
env = Environment(loader=PackageLoader('past', 'templates'))
env.filters['wrap_long_line'] = wrap_long_line
env.filters['nl2br'] = filters.nl2br
env.filters['stream_time'] = filters.stream_time
env.filters['clear_html_element'] = clear_html_element
env.filters['isstr'] = lambda x: isinstance(x, basestring)
t = env.get_template('status.html')
m = t.module
for s in status_list:
if not s:
continue
if s.category == config.CATE_DOUBAN_STATUS:
r = m.douban_status(s, pdf=True)
elif s.category == config.CATE_SINA_STATUS:
r = m.sina_status(s, pdf=True)
elif s.category == config.CATE_TWITTER_STATUS:
r = m.twitter_status(s, pdf=True)
elif s.category == config.CATE_QQWEIBO_STATUS:
r = m.qq_weibo_status(s, pdf=True)
elif s.category == config.CATE_WORDPRESS_POST:
r = m.wordpress_status(s, pdf=True)
elif s.category == config.CATE_THEPAST_NOTE:
r = m.thepast_note_status(s, pdf=True)
elif s.category == config.CATE_RENREN_STATUS:
r = m.thepast_renren_status(s, pdf=True)
elif s.category == config.CATE_RENREN_BLOG:
r = m.thepast_renren_blog(s, pdf=True)
elif s.category == config.CATE_RENREN_PHOTO or s.category == config.CATE_RENREN_ALBUM:
r = m.thepast_renren_photo(s, pdf=True)
elif s.category == config.CATE_INSTAGRAM_STATUS:
r = m.thepast_default_status(s, pdf=True)
else:
r = ''
if not r:
continue
_html += '''<div class="cell">''' + r + '''</div>'''
Status._clear_cache(user_id = s.user_id, status_id = s.id)
_html += """</div></body></html>"""
return _html
示例12: timeline
def timeline():
ids = Status.get_ids(user_id=g.user.id, start=g.start, limit=g.count, cate=g.cate)
status_list = Status.gets(ids)
status_list = statuses_timelize(status_list)
if status_list:
tags_list = [x[0] for x in get_keywords(g.user.id, 30)]
else:
tags_list = []
intros = [g.user.get_thirdparty_profile(x).get("intro") for x in config.OPENID_TYPE_DICT.values()]
intros = filter(None, intros)
return render_template("timeline.html", user=g.user, tags_list=tags_list,
intros=intros, status_list=status_list, config=config)
示例13: render
def render(user, status_list, with_head=True):
if not status_list:
return
date = status_list[0].create_time.strftime("%Y年%m月")
date = date.decode("utf8")
if with_head:
_html = u"""<html> <body>
<div id="Top">
<img src="%s"/> The Past of Me | 个人杂志计划 %s CopyRight©%s
<br/>
</div>
<br/> <br/>
<div class="box">
""" % (
os.path.join(app.root_path, "static/img/logo.png"),
date,
user.name,
)
else:
_html = u"""<html> <body><div class="box">"""
from jinja2 import Environment, PackageLoader
env = Environment(loader=PackageLoader("past", "templates"))
env.filters["wrap_long_line"] = wrap_long_line
env.filters["nl2br"] = filters.nl2br
env.filters["clear_html_element"] = clear_html_element
t = env.get_template("status.html")
m = t.module
for s in status_list:
if not s:
continue
if s.category == config.CATE_DOUBAN_STATUS:
r = m.douban_status(s, pdf=True)
elif s.category == config.CATE_SINA_STATUS:
r = m.sina_status(s, pdf=True)
elif s.category == config.CATE_TWITTER_STATUS:
r = m.twitter_status(s, pdf=True)
elif s.category == config.CATE_QQWEIBO_STATUS:
r = m.qq_weibo_status(s, pdf=True)
elif s.category == config.CATE_WORDPRESS_POST:
r = m.wordpress_status(s, pdf=True)
elif s.category == config.CATE_THEPAST_NOTE:
r = m.thepast_note_status(s, pdf=True)
else:
r = ""
if not r:
continue
_html += """<div class="cell">""" + r + """</div>"""
Status._clear_cache(user_id=s.user_id, status_id=s.id)
_html += """</div></body></html>"""
return _html
示例14: user
def user(uid):
u = User.get(uid)
if not u:
abort(404, "no such user")
if g.user and g.user.id == u.id:
return redirect(url_for("index"))
#TODO:增加可否查看其他用户的权限检查
cate = request.args.get("cate", None)
ids = Status.get_ids(user_id=u.id, start=g.start, limit=g.count, cate=g.cate)
status_list = Status.gets(ids)
return render_template("timeline.html", user=u, status_list=status_list, config=config)
示例15: remove_status
def remove_status(uid):
cursor = db_conn.execute("select id from status where user_id=%s", uid)
if cursor:
rows = cursor.fetchall()
for row in rows:
sid = row[0]
print "---- delete mongo text, sid=", sid
RawStatus.remove(sid)
print "---- delete from status, uid=", uid
db_conn.execute("delete from status where user_id=%s", uid)
db_conn.commit()
Status._clear_cache(uid, None)