当前位置: 首页>>代码示例>>Python>>正文


Python Account._query方法代码示例

本文整理汇总了Python中r2.models.Account._query方法的典型用法代码示例。如果您正苦于以下问题:Python Account._query方法的具体用法?Python Account._query怎么用?Python Account._query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在r2.models.Account的用法示例。


在下文中一共展示了Account._query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: clear_account_by_name_cache

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _query [as 别名]
def clear_account_by_name_cache():
    q = Account._query(Account.c._deleted == (True, False), data = True)
    for account in q:
        name = account.name
        clear_memo('account._by_name', Account, name.lower(), True)
        clear_memo('account._by_name', Account, name.lower(), False)
        print "Cleared cache for %s" % account.name
开发者ID:AndrewHay,项目名称:lesswrong,代码行数:9,代码来源:clear_cache.py

示例2: reset_last_email_sent_at_for_all_accounts

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _query [as 别名]
def reset_last_email_sent_at_for_all_accounts():
    start_of_epoc = pytz.utc.localize(datetime.datetime.utcfromtimestamp(0))

    accounts = fetch_things2(Account._query(Account.c.email != None, sort=asc('_date')))
    for account in accounts:
        account.last_email_sent_at = start_of_epoc
        account._commit()
开发者ID:caseypatrickdriscoll,项目名称:reddit,代码行数:9,代码来源:summary_email.py

示例3: test_cassasavehide

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _query [as 别名]
def test_cassasavehide():
    from r2.models import Account, Link, CassandraSave, SavesByAccount
    from r2.lib.db import tdb_cassandra

    a = list(Account._query(sort=desc('_date'),
                            limit=1))[0]
    l = list(Link._query(sort=desc('_date'),
                         limit=1))[0]

    try:
        csh = CassandraSave._fast_query(a._id36, l._id36)
        print "Warning! Deleting!", csh
        CassandraSave._fast_query(a._id36, l._id36)._destroy()
    except tdb_cassandra.NotFound:
        pass

    csh = CassandraSave._save(a, l)
    csh._commit()
    assert CassandraSave._fast_query(a._id36, l._id36) == csh

    # check for the SavesByAccount object too
    assert SavesByAccount._byID(a._id36)[csh._id] == csh._id

    csh._destroy()

    try:
        CassandraSave._fast_query(a._id36, l._id36) == csh
        raise Exception("shouldn't exist after destroying")
    except tdb_cassandra.NotFound:
        pass

    try:
        assert csh._id not in SavesByAccount._byID(a._id36, properties = csh._id)._values()
    except tdb_cassandra.NotFound:
        pass
开发者ID:Anenome,项目名称:reddit,代码行数:37,代码来源:cassamodels.py

示例4: write_karmas

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _query [as 别名]
    def write_karmas(self):
        STEP = 100
        account_id_max = sa.select([sa.func.max(karmatotals.c.account_id)]).scalar()
        account_id_start = 0  #int(self.state.kvstore.get('karma.cur_write_account_id', '0'))

        print('Writing karma keys, starting at account {0}, max account id is {1}'.format(
            account_id_start, account_id_max))

        for account_id_low in xrange(account_id_start, account_id_max + 1, STEP):
            accounts = list(Account._query(
                Account.c._id >= account_id_low,
                Account.c._id < account_id_low + STEP))
            accounts = dict((a._id, a) for a in accounts)
            karmas = karmatotals.select(
                sa.and_(karmatotals.c.account_id >= account_id_low,
                        karmatotals.c.account_id < account_id_low + STEP)).execute().fetchall()

            print('{0}: writing karmas, {1} of {2} accounts'.format(
                datetime.now().isoformat(' '), account_id_low, account_id_max))

            for k in karmas:
                account = accounts.get(k['account_id'])
                if account is not None:
                    key = self.make_karma_key(k)
                    setattr(account, key, k['amount'])

            for ac in accounts.values():
                ac._commit()
开发者ID:EeroHeikkinen,项目名称:ikaros,代码行数:30,代码来源:recalc_karma.py

示例5: test_send_summary_emails

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _query [as 别名]
def test_send_summary_emails():
    accounts = fetch_things2(Account._query(Account.c.email != None, sort=asc('_date')))
    for account in accounts:
        a_day_ago = datetime.datetime.now(pytz.utc) - datetime.timedelta(hours=24)
        account.last_email_sent_at = a_day_ago
        account._commit()
        send_account_summary_email(account._id, verbose=True)
开发者ID:caseypatrickdriscoll,项目名称:reddit,代码行数:9,代码来源:summary_email.py

示例6: gen_keys

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _query [as 别名]
    def gen_keys():
        yield promoted_memo_key

        # just let this one do its own writing
        load_all_reddits()

        yield queries.get_all_comments().iden

        l_q = Link._query(Link.c._spam == (True, False),
                          Link.c._deleted == (True, False),
                          sort=desc('_date'),
                          data=True,
                          )
        for link in fetch_things2(l_q, verbosity):
            yield comments_key(link._id)
            yield last_modified_key(link, 'comments')

        a_q = Account._query(Account.c._spam == (True, False),
                             sort=desc('_date'),
                             )
        for account in fetch_things2(a_q, verbosity):
            yield messages_key(account._id)
            yield last_modified_key(account, 'overview')
            yield last_modified_key(account, 'commented')
            yield last_modified_key(account, 'submitted')
            yield last_modified_key(account, 'liked')
            yield last_modified_key(account, 'disliked')
            yield queries.get_comments(account, 'new', 'all').iden
            yield queries.get_submitted(account, 'new', 'all').iden
            yield queries.get_liked(account).iden
            yield queries.get_disliked(account).iden
            yield queries.get_hidden(account).iden
            yield queries.get_saved(account).iden
            yield queries.get_inbox_messages(account).iden
            yield queries.get_unread_messages(account).iden
            yield queries.get_inbox_comments(account).iden
            yield queries.get_unread_comments(account).iden
            yield queries.get_inbox_selfreply(account).iden
            yield queries.get_unread_selfreply(account).iden
            yield queries.get_sent(account).iden

        sr_q = Subreddit._query(Subreddit.c._spam == (True, False),
                                sort=desc('_date'),
                                )
        for sr in fetch_things2(sr_q, verbosity):
            yield last_modified_key(sr, 'stylesheet_contents')
            yield queries.get_links(sr, 'hot', 'all').iden
            yield queries.get_links(sr, 'new', 'all').iden

            for sort in 'top', 'controversial':
                for time in 'hour', 'day', 'week', 'month', 'year', 'all':
                    yield queries.get_links(sr, sort, time,
                                            merge_batched=False).iden
            yield queries.get_spam_links(sr).iden
            yield queries.get_spam_comments(sr).iden
            yield queries.get_reported_links(sr).iden
            yield queries.get_reported_comments(sr).iden
            yield queries.get_subreddit_messages(sr).iden
            yield queries.get_unread_subreddit_messages(sr).iden
开发者ID:MatsT,项目名称:reddit,代码行数:61,代码来源:migrate.py

示例7: _query_account

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _query [as 别名]
 def _query_account(self, *args):
     account = None
     kwargs = {'data': True}
     q = Account._query(*args, **kwargs)
     accounts = list(q)
     if accounts:
         account = accounts[0]
     return account
开发者ID:AndrewHay,项目名称:lesswrong,代码行数:10,代码来源:importer.py

示例8: cancel_subscription

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _query [as 别名]
def cancel_subscription(subscr_id):
    q = Account._query(Account.c.gold_subscr_id == subscr_id, data=True)
    l = list(q)
    if len(l) != 1:
        g.log.warning("Found %d matches for canceled subscription %s" % (len(l), subscr_id))
    for account in l:
        account.gold_subscr_id = None
        account._commit()
        g.log.info("%s canceled their recurring subscription %s" % (account.name, subscr_id))
开发者ID:nmargono,项目名称:reddit,代码行数:11,代码来源:admintools.py

示例9: accountid_from_paypalsubscription

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _query [as 别名]
def accountid_from_paypalsubscription(subscr_id):
    if subscr_id is None:
        return None

    q = Account._query(Account.c.gold_subscr_id == subscr_id, data=False)
    l = list(q)
    if l:
        return l[0]._id
    else:
        return None
开发者ID:nmargono,项目名称:reddit,代码行数:12,代码来源:admintools.py

示例10: get_users_to_notify_for_meetup

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _query [as 别名]
def get_users_to_notify_for_meetup(coords):
    # This query could definitely be optimized, but I don't expect it to be
    # run too often, so it's probably not worth the effort.
    users = Account._query(
        Account.c.pref_meetup_notify_enabled == True,
        Account.c.email != None,
        Account.c.pref_latitude != None,
        Account.c.pref_longitude != None)
    users = filter(lambda u: u.is_within_radius(coords, u.pref_meetup_notify_radius), users)
    return list(users)
开发者ID:EeroHeikkinen,项目名称:ikaros,代码行数:12,代码来源:notify.py

示例11: accountid_from_subscription

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _query [as 别名]
def accountid_from_subscription(subscr_id):
    if subscr_id is None:
        return None

    q = Account._query(Account.c.gold_subscr_id == subscr_id,
                       Account.c._spam == (True, False),
                       Account.c._deleted == (True, False), data=False)
    l = list(q)
    if l:
        return l[0]._id
    else:
        return None
开发者ID:CrypticCraig,项目名称:reddit,代码行数:14,代码来源:admintools.py

示例12: gen_keys

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _query [as 别名]
    def gen_keys():
        yield promoted_memo_key

        # just let this one do its own writing
        load_all_reddits()

        yield queries.get_all_comments().iden

        l_q = Link._query(
            Link.c._spam == (True, False), Link.c._deleted == (True, False), sort=desc("_date"), data=True
        )
        for link in fetch_things2(l_q, verbosity):
            yield comments_key(link._id)
            yield last_modified_key(link, "comments")

        a_q = Account._query(Account.c._spam == (True, False), sort=desc("_date"))
        for account in fetch_things2(a_q, verbosity):
            yield messages_key(account._id)
            yield last_modified_key(account, "overview")
            yield last_modified_key(account, "commented")
            yield last_modified_key(account, "submitted")
            yield last_modified_key(account, "liked")
            yield last_modified_key(account, "disliked")
            yield queries.get_comments(account, "new", "all").iden
            yield queries.get_submitted(account, "new", "all").iden
            yield queries.get_liked(account).iden
            yield queries.get_disliked(account).iden
            yield queries.get_hidden(account).iden
            yield queries.get_saved(account).iden
            yield queries.get_inbox_messages(account).iden
            yield queries.get_unread_messages(account).iden
            yield queries.get_inbox_comments(account).iden
            yield queries.get_unread_comments(account).iden
            yield queries.get_inbox_selfreply(account).iden
            yield queries.get_unread_selfreply(account).iden
            yield queries.get_sent(account).iden

        sr_q = Subreddit._query(Subreddit.c._spam == (True, False), sort=desc("_date"))
        for sr in fetch_things2(sr_q, verbosity):
            yield last_modified_key(sr, "stylesheet_contents")
            yield queries.get_links(sr, "hot", "all").iden
            yield queries.get_links(sr, "new", "all").iden

            for sort in "top", "controversial":
                for time in "hour", "day", "week", "month", "year", "all":
                    yield queries.get_links(sr, sort, time, merge_batched=False).iden
            yield queries.get_spam_links(sr).iden
            yield queries.get_spam_comments(sr).iden
            yield queries.get_reported_links(sr).iden
            yield queries.get_reported_comments(sr).iden
            yield queries.get_subreddit_messages(sr).iden
            yield queries.get_unread_subreddit_messages(sr).iden
开发者ID:Shilohtd,项目名称:reddit,代码行数:54,代码来源:migrate.py

示例13: all_users

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _query [as 别名]
def all_users():
    q = Account._query(or_(Account.c.link_karma != 0,
                           Account.c.comment_karma != 0),
                       Account.c._spam == (True, False),
                       Account.c._deleted == (True, False),
                       sort = desc('_date'),
                       limit = 200,
                       data = True)
    users = list(q)
    while users:
        for l in users:
            yield l
        users = list(q._after(l))
开发者ID:ArslanRafique,项目名称:reddit,代码行数:15,代码来源:update_karmas.py

示例14: user_sort_options

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _query [as 别名]
def user_sort_options():
    pref = 'browse_sort'
    users = Account._query(data=True)
    for user in users:
        print user.name,
        user_prefs = copy(user.sort_options)
        user_pref = user_prefs.get(pref)
        if user_pref and user_pref == 'all':
            user_prefs[pref] = 'quarter'
            user.sort_options = user_prefs
            user._commit()
            print " *"
        else:
            print
开发者ID:EeroHeikkinen,项目名称:ikaros,代码行数:16,代码来源:user_sort_options.py

示例15: geolocate_users

# 需要导入模块: from r2.models import Account [as 别名]
# 或者: from r2.models.Account import _query [as 别名]
def geolocate_users():
    users = list(Account._query(Account.c.pref_location != None,
                                data=True))
    log('Geolocating {0} users...'.format(len(users)))

    for user in users:
        if not user.pref_location or user.pref_latitude:
            continue
        coords = geolocate_address(user.pref_location)
        if coords:
            user.pref_latitude, user.pref_longitude = coords
            user._commit()
            log('{0} ({1!r}) => ({2:.3}, {3:.3})'.format(
                user.name, user.pref_location, user.pref_latitude, user.pref_longitude))
开发者ID:EeroHeikkinen,项目名称:ikaros,代码行数:16,代码来源:geolocate_users.py


注:本文中的r2.models.Account._query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。