コード例 #1
0
ファイル: admintools.py プロジェクト: slimlife/cookie
def update_gold_users():
    now = datetime.now(g.display_tz)
    warning_days = 3
    renew_msg = _("[Click here for details on how to set up an "
                  "automatically-renewing subscription or to renew.]"
                  "(/gold) If you have any thoughts, complaints, "
                  "rants, suggestions about reddit gold, please write "
                  "to us at %(gold_email)s. Your feedback would be "
                  "much appreciated.\n\nThank you for your past "
                  "patronage.") % {
                      'gold_email': g.goldsupport_email
                  }

    for account in all_gold_users():
        days_left = (account.gold_expiration - now).days
        if days_left < 0:
            if account.pref_creddit_autorenew:
                with creddits_lock(account):
                    if account.gold_creddits > 0:
                        admintools.adjust_gold_expiration(account, days=31)
                        account.gold_creddits -= 1
                        account._commit()
                        continue

            admintools.degolden(account)

            subject = _("Your reddit gold subscription has expired.")
            message = _("Your subscription to reddit gold has expired.")
            message += "\n\n" + renew_msg
            message = append_random_bottlecap_phrase(message)

            send_system_message(account,
                                subject,
                                message,
                                distinguished='gold-auto')
        elif days_left <= warning_days and not account.gold_will_autorenew:
            hc_key = "gold_expiration_notice-" + account.name
            already_warned = g.hardcache.get(hc_key)
            if not already_warned:
                g.hardcache.set(hc_key, True, 86400 * (warning_days + 1))

                subject = _("Your reddit gold subscription is about to "
                            "expire!")
                message = _("Your subscription to reddit gold will be "
                            "expiring soon.")
                message += "\n\n" + renew_msg
                message = append_random_bottlecap_phrase(message)

                send_system_message(account,
                                    subject,
                                    message,
                                    distinguished='gold-auto')
コード例 #2
0
ファイル: admintools.py プロジェクト: CrypticCraig/reddit
def update_gold_users():
    now = datetime.now(g.display_tz)
    warning_days = 3
    renew_msg = _("[Click here for details on how to set up an "
                  "automatically-renewing subscription or to renew.]"
                  "(/gold) If you have any thoughts, complaints, "
                  "rants, suggestions about reddit gold, please write "
                  "to us at %(gold_email)s. Your feedback would be "
                  "much appreciated.\n\nThank you for your past "
                  "patronage.") % {'gold_email': g.goldsupport_email}

    for account in all_gold_users():
        days_left = (account.gold_expiration - now).days
        if days_left < 0:
            if account.pref_creddit_autorenew:
                with creddits_lock(account):
                    if account.gold_creddits > 0:
                        admintools.adjust_gold_expiration(account, days=31)
                        account.gold_creddits -= 1
                        account._commit()
                        continue

            admintools.degolden(account)

            subject = _("Your reddit gold subscription has expired.")
            message = _("Your subscription to reddit gold has expired.")
            message += "\n\n" + renew_msg
            message = append_random_bottlecap_phrase(message)

            send_system_message(account, subject, message,
                                distinguished='gold-auto')
        elif days_left <= warning_days and not account.gold_will_autorenew:
            hc_key = "gold_expiration_notice-" + account.name
            already_warned = g.hardcache.get(hc_key)
            if not already_warned:
                g.hardcache.set(hc_key, True, 86400 * (warning_days + 1))
                
                subject = _("Your reddit gold subscription is about to "
                            "expire!")
                message = _("Your subscription to reddit gold will be "
                            "expiring soon.")
                message += "\n\n" + renew_msg
                message = append_random_bottlecap_phrase(message)

                send_system_message(account, subject, message,
                                    distinguished='gold-auto')
コード例 #3
0
ファイル: admintools.py プロジェクト: AJRenold/reddit
def update_gold_users(verbose=False):
    now = datetime.now(g.display_tz)
    minimum = None
    count = 0
    expiration_dates = {}

    renew_msg = _("[Click here for details on how to set up an "
                  "automatically-renewing subscription or to renew.]"
                  "(/gold) If you have any thoughts, complaints, "
                  "rants, suggestions about reddit gold, please write "
                  "to us at %(gold_email)s. Your feedback would be "
                  "much appreciated.\n\nThank you for your past "
                  "patronage.") % {'gold_email': g.goldthanks_email}

    for account in all_gold_users():
        if not hasattr(account, "gold_expiration"):
            g.log.error("%s has no gold_expiration" % account.name)
            continue

        delta = account.gold_expiration - now
        days_left = delta.days

        hc_key = "gold_expiration_notice-" + account.name

        if days_left < 0:
            if verbose:
                print "%s just expired" % account.name
            admintools.degolden(account)
            subject = _("Your reddit gold subscription has expired.")
            message = _("Your subscription to reddit gold has expired.")
            message += "\n\n" + renew_msg
            message = append_random_bottlecap_phrase(message)

            send_system_message(account, subject, message,
                                distinguished='gold-auto')
            continue

        count += 1

        if verbose:
            exp_date = account.gold_expiration.strftime('%Y-%m-%d')
            expiration_dates.setdefault(exp_date, 0)
            expiration_dates[exp_date] += 1

#           print "%s expires in %d days" % (account.name, days_left)
            if minimum is None or delta < minimum[0]:
                minimum = (delta, account)

        if days_left <= 3 and not g.hardcache.get(hc_key):
            if verbose:
                print "%s expires soon: %s days" % (account.name, days_left)
            if account.has_gold_subscription:
                if verbose:
                    print "Not sending notice to %s (%s)" % (account.name,
                                                     account.gold_subscr_id)
            else:
                if verbose:
                    print "Sending notice to %s" % account.name
                g.hardcache.set(hc_key, True, 86400 * 10)
                subject = _("Your reddit gold subscription is about to "
                            "expire!")
                message = _("Your subscription to reddit gold will be "
                            "expiring soon.")
                message += "\n\n" + renew_msg
                message = append_random_bottlecap_phrase(message)

                send_system_message(account, subject, message,
                                    distinguished='gold-auto')

    if verbose:
        for exp_date in sorted(expiration_dates.keys()):
            num_expiring = expiration_dates[exp_date]
            print '%s %3d %s' % (exp_date, num_expiring, '*' * num_expiring)
        print "%s goldmembers" % count
        if minimum is None:
            print "Nobody found."
        else:
            delta, account = minimum
            print "Next expiration is %s, in %d days" % (account.name, delta.days)
コード例 #4
0
def update_gold_users(verbose=False):
    now = datetime.now(g.display_tz)
    minimum = None
    count = 0
    expiration_dates = {}

    renew_msg = _("[Click here for details on how to set up an "
                  "automatically-renewing subscription or to renew.]"
                  "(/gold) If you have any thoughts, complaints, "
                  "rants, suggestions about reddit gold, please write "
                  "to us at %(gold_email)s. Your feedback would be "
                  "much appreciated.\n\nThank you for your past "
                  "patronage.") % {'gold_email': g.goldthanks_email}

    for account in all_gold_users():
        if not hasattr(account, "gold_expiration"):
            g.log.error("%s has no gold_expiration" % account.name)
            continue

        delta = account.gold_expiration - now
        days_left = delta.days

        hc_key = "gold_expiration_notice-" + account.name

        if days_left < 0:
            if verbose:
                print "%s just expired" % account.name
            admintools.degolden(account)
            subject = _("Your reddit gold subscription has expired.")
            message = _("Your subscription to reddit gold has expired.")
            message += "\n\n" + renew_msg
            message = append_random_bottlecap_phrase(message)

            send_system_message(account, subject, message,
                                distinguished='gold-auto')
            continue

        count += 1

        if verbose:
            exp_date = account.gold_expiration.strftime('%Y-%m-%d')
            expiration_dates.setdefault(exp_date, 0)
            expiration_dates[exp_date] += 1

#           print "%s expires in %d days" % (account.name, days_left)
            if minimum is None or delta < minimum[0]:
                minimum = (delta, account)

        if days_left <= 3 and not g.hardcache.get(hc_key):
            if verbose:
                print "%s expires soon: %s days" % (account.name, days_left)
            if account.has_gold_subscription:
                if verbose:
                    print "Not sending notice to %s (%s)" % (account.name,
                                                     account.gold_subscr_id)
            else:
                if verbose:
                    print "Sending notice to %s" % account.name
                g.hardcache.set(hc_key, True, 86400 * 10)
                subject = _("Your reddit gold subscription is about to "
                            "expire!")
                message = _("Your subscription to reddit gold will be "
                            "expiring soon.")
                message += "\n\n" + renew_msg
                message = append_random_bottlecap_phrase(message)

                send_system_message(account, subject, message,
                                    distinguished='gold-auto')

    if verbose:
        for exp_date in sorted(expiration_dates.keys()):
            num_expiring = expiration_dates[exp_date]
            print '%s %3d %s' % (exp_date, num_expiring, '*' * num_expiring)
        print "%s goldmembers" % count
        if minimum is None:
            print "Nobody found."
        else:
            delta, account = minimum
            print "Next expiration is %s, in %d days" % (account.name, delta.days)