Example #1
0
    def __init__(self, *args, **kwargs):
        nav_buttons = [
            NavButton(_("overview"), "/advertising"),
            OffsiteButton(
                _("getting started"),
                "https://reddit.zendesk.com/hc/en-us/articles/205118995-Step-by-step-How-to-create-an-ad",
            ),
            OffsiteButton(
                _("audience"), "https://reddit.zendesk.com/hc/en-us/articles/205183225-Audience-and-Demographics"
            ),
            OffsiteButton(
                _("best practices"), "https://reddit.zendesk.com/hc/en-us/sections/200863319-Best-Practices-Tips"
            ),
            OffsiteButton(_("help center"), "https://reddit.zendesk.com/hc/en-us/categories/200352595-Advertising-"),
            NavButton(
                _("manage ads"),
                "/promoted?utm_source=advertising&utm_medium=button&utm_term=manage%20ads&utm_campaign=buttons",
            ),
        ]

        self.create_ad_url = (
            "/promoted/new_promo?utm_source=advertising&utm_medium=button&utm_term=create%20ads&utm_campaign=buttons"
        )

        self.nav_menu = NavMenu(
            nav_buttons, type="flatlist", base_path="", css_class="advertising-menu", separator=None
        ).render()

        sections = SelfServeContent.get_all(return_dict=True)
        self.banner = sections.get("banner")
        self.info = sections.get("info")
        self.advertisers = sections.get("advertisers")
        self.subreddit = sections.get("subreddit")
        self.help = sections.get("help")
        blurbs = SelfServeBlurb.get_all(return_dict=True)
        if "platform" in blurbs:
            min_cpm = min(
                [g.cpm_selfserve_collection.decimal, g.cpm_selfserve.decimal, g.cpm_selfserve_geotarget_metro.decimal]
            )
            formatted_min_cpm = format_currency(min_cpm, "USD", locale=c.locale)
            formatted_min_bid = format_currency(g.min_promote_bid, "USD", locale=c.locale)
            blurbs["platform"].text = (
                blurbs["platform"]
                .text.replace("[min_promote_bid]", formatted_min_bid)
                .replace("[cpm_selfserve]", formatted_min_cpm)
            )
        self.blurbs = blurbs.values()
        self.advertiser_logos = SelfServeAdvertiser.get_all()
        self.quotes = SelfServeQuote.get_all()
        self.help_text = None
        try:
            self.help_text = WikiPage.get(Frontpage, g.wiki_page_selfserve_help).content
        except NotFound:
            pass
        Templated.__init__(self, *args, **kwargs)
Example #2
0
    def __init__(self, *args, **kwargs):
        nav_buttons = [
            NavButton(_('overview'), '/advertising'),
            OffsiteButton(_('getting started'), 'https://reddit.zendesk.com/hc/en-us/articles/205118995-Step-by-step-How-to-create-an-ad'),
            OffsiteButton(_('audience'), 'https://reddit.zendesk.com/hc/en-us/articles/205183225-Audience-and-Demographics'),
            OffsiteButton(_('best practices'), 'https://reddit.zendesk.com/hc/en-us/sections/200863319-Best-Practices-Tips'),
            OffsiteButton(_('help center'), 'https://reddit.zendesk.com/hc/en-us/categories/200352595-Advertising-'),
            NavButton(_('manage ads'), '/promoted?utm_source=advertising&utm_medium=button&utm_term=manage%20ads&utm_campaign=buttons'),
        ]

        self.create_ad_url = '/promoted/new_promo?utm_source=advertising&utm_medium=button&utm_term=create%20ads&utm_campaign=buttons'

        self.nav_menu = NavMenu(nav_buttons,
            type='flatlist',
            base_path='',
            css_class='advertising-menu',
            separator=None).render()

        sections = SelfServeContent.get_all(return_dict=True)
        self.banner = sections.get('banner')
        self.info = sections.get('info')
        self.advertisers = sections.get('advertisers')
        self.subreddit = sections.get('subreddit')
        self.help = sections.get('help')
        blurbs = SelfServeBlurb.get_all(return_dict=True)
        if 'platform' in blurbs:
            min_cpm = min([
                g.cpm_selfserve_collection.decimal,
                g.cpm_selfserve.decimal,
                g.cpm_selfserve_geotarget_metro.decimal,
            ])
            formatted_min_cpm = format_currency(min_cpm, 'USD', locale=c.locale)
            formatted_min_budget = format_currency(
                g.min_total_budget_pennies / 100., 'USD', locale=c.locale)
            blurbs['platform'].text = blurbs['platform'].text.replace(
                '[min_promote_bid]', formatted_min_budget).replace(
                '[cpm_selfserve]', formatted_min_cpm)
        self.blurbs = blurbs.values()
        self.advertiser_logos = SelfServeAdvertiser.get_all()
        self.quotes = SelfServeQuote.get_all()
        self.help_text = None
        try:
            self.help_text = WikiPage.get(Frontpage, g.wiki_page_selfserve_help).content
        except NotFound:
            pass
        Templated.__init__(self, *args, **kwargs)
    def __init__(self, *args, **kwargs):
        nav_buttons = [
            NavButton(_('overview'), '/advertising'),
            NavButton(_('getting started'), '/wiki/selfservenew?utm_source=advertising&utm_medium=button&utm_term=getting%20started&utm_campaign=buttons'),
            NavButton(_('audience'), '/wiki/mediakit?utm_source=advertising&utm_medium=button&utm_term=audience&utm_campaign=buttons'),
            NavButton(_('best practices'), '/wiki/brandiquette?utm_source=advertising&utm_medium=button&utm_term=best%20practices&utm_campaign=buttons'),
            NavButton(_('help center'), '/wiki/selfserve?utm_source=advertising&utm_medium=button&utm_term=help%20center&utm_campaign=buttons'),
            NavButton(_('manage ads'), '/promoted?utm_source=advertising&utm_medium=button&utm_term=manage%20ads&utm_campaign=buttons'),
        ]

        self.create_ad_url = '/promoted/new_promo?utm_source=advertising&utm_medium=button&utm_term=create%20ads&utm_campaign=buttons'

        self.nav_menu = NavMenu(nav_buttons,
            type='flatlist',
            base_path='',
            css_class='advertising-menu',
            separator=None).render()

        sections = SelfServeContent.get_all(return_dict=True)
        self.banner = sections.get('banner')
        self.info = sections.get('info')
        self.advertisers = sections.get('advertisers')
        self.subreddit = sections.get('subreddit')
        self.help = sections.get('help')
        blurbs = SelfServeBlurb.get_all(return_dict=True)
        if 'platform' in blurbs:
            min_cpm = min([
                g.cpm_selfserve_collection.decimal,
                g.cpm_selfserve.decimal,
                g.cpm_selfserve_geotarget_metro.decimal,
            ])
            formatted_min_cpm = format_currency(min_cpm, 'USD', locale=c.locale)
            formatted_min_bid = format_currency(g.min_promote_bid, 'USD', locale=c.locale)
            blurbs['platform'].text = blurbs['platform'].text.replace(
                '[min_promote_bid]', formatted_min_bid).replace(
                '[cpm_selfserve]', formatted_min_cpm)
        self.blurbs = blurbs.values()
        self.advertiser_logos = SelfServeAdvertiser.get_all()
        self.quotes = SelfServeQuote.get_all()
        self.help_text = None
        try:
            self.help_text = WikiPage.get(Frontpage, g.wiki_page_selfserve_help).content
        except NotFound:
            pass
        Templated.__init__(self, *args, **kwargs)
Example #4
0
    def process_message(msg):
        if not ACCOUNT:
            return

        fullname = msg.body
        item = Thing._by_fullname(fullname, data=True)
        if not isinstance(item, (Link, Comment)):
            return

        subreddit = item.subreddit_slow

        wiki_page_id = wiki_id(subreddit._id36, "config/automoderator")
        wiki_page_fullname = "WikiPage_%s" % wiki_page_id
        last_edited = LastModified.get(wiki_page_fullname, "Edit")
        if not last_edited:
            return

        # initialize rules for the subreddit if we haven't already
        # or if the page has been edited since we last initialized
        need_to_init = False
        if subreddit._id not in rules_by_subreddit:
            need_to_init = True
        else:
            rules = rules_by_subreddit[subreddit._id]
            if last_edited > rules.init_time:
                need_to_init = True

        if need_to_init:
            wp = WikiPage.get(subreddit, "config/automoderator")
            rules = Ruleset(wp.content)
            rules_by_subreddit[subreddit._id] = rules

        if not rules:
            return

        try:
            TimeoutFunction(rules.apply_to_item, 2)(item)
            print "Checked %s from /r/%s" % (item, subreddit.name)
        except TimeoutFunctionException:
            print "Timed out on %s from /r/%s" % (item, subreddit.name)
        except KeyboardInterrupt:
            raise
        except:
            print "Error on %s from /r/%s" % (item, subreddit.name)
            print traceback.format_exc()
Example #5
0
    def __init__(self, yaml_text=""):
        """Create a collection of Rules from YAML documents."""
        self.init_time = datetime.now(g.tz)
        self.rules = []

        if not yaml_text:
            return

        # force loading all the yaml documents to check for errors
        try:
            rule_defs = list(yaml.safe_load_all(yaml_text))
        except Exception as e:
            raise ValueError("YAML parsing error: %s" % e)

        # drop any sections that aren't dicts (generally just comments)
        rule_defs = [rule_def for rule_def in rule_defs if isinstance(rule_def, dict)]

        if any("standard" in rule_def for rule_def in rule_defs):
            # load standard rules from wiki page
            standard_rules = {}
            try:
                wp = WikiPage.get(Frontpage, "automoderator_standards")
                standard_defs = yaml.safe_load_all(wp.content)
                for standard_def in standard_defs:
                    name = standard_def.pop("standard")
                    standard_rules[name] = standard_def
            except Exception as e:
                g.log.error("Error while loading automod standards: %s", e)
                standard_rules = None

        for values in rule_defs:
            orig_values = values.copy()
            # use standard rule as a base if they defined one
            standard_name = values.pop("standard", None)
            if standard_name:
                # error while loading the standards, skip this rule
                if standard_rules is None:
                    continue

                standard_values = None
                if isinstance(standard_name, basestring):
                    standard_values = standard_rules.get(standard_name, None)
                if not standard_values:
                    raise AutoModeratorSyntaxError("Invalid standard: `%s`" % standard_name, yaml.dump(orig_values))

                new_values = standard_values.copy()
                new_values.update(values)
                values = new_values

            type = values.get("type", "any")
            if type == "any":
                # try to create two Rules for comments and links
                for type_value in ("comment", "submission"):
                    values["type"] = type_value
                    try:
                        rule = Rule(values)
                    except AutoModeratorRuleTypeError:
                        continue

                    # only keep the rule if it had any checks
                    if rule.has_any_checks(targets_only=True):
                        self.rules.append(Rule(values))
            else:
                self.rules.append(Rule(values))

        # drop any rules that don't have a check and an action
        self.rules = [rule for rule in self.rules if rule.has_any_checks() and rule.has_any_actions()]

        self.rules.sort(key=lambda r: r.priority, reverse=True)