<commit_before># This file is part of fedmsg.
# Copyright (C) 2012, 2013 Red Hat, Inc.
#
# fedmsg is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# fedmsg is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with fedmsg; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Authors:  <NAME> <<EMAIL>>
#           <NAME> <<EMAIL>>

from fasshim import gravatar_url
from fedmsg_meta_fedora_infrastructure import BaseProcessor


class BadgesProcessor(BaseProcessor):
    __name__ = "fedbadges"
    __description__ = "the Fedora Open Badges System"
    __link__ = "https://badges.fedoraproject.org/"
    __docs__ = "https://fedoraproject.org/wiki/Open_Badges"
    __obj__ = "New Badges"

    def _get_user(self, msg):
        if 'badge.award' in msg['topic']:
            return msg['msg']['user']['username']
        else:
            return msg['msg']['person']['nickname']

    def link(self, msg, **config):
        username = self._get_user(msg)
        return "https://badges.fedoraproject.org/user/%s" % username

    def subtitle(self, msg, **config):
        user = self._get_user(msg)
        if 'badge.award' in msg['topic']:
            name = msg['msg']['badge']['name']
            tmpl = self._('{user} has been awarded the "{name}" badge')
            return tmpl.format(user=user, name=name)
        else:
            rank = msg['msg']['person']['rank']
            tmpl = self._('{user} moved to position {rank} '
                          'on the badges leaderboard')
            return tmpl.format(user=user, rank=rank)

    def icon(self, msg, **config):
        if 'badge.award' in msg['topic']:
            return msg['msg']['badge']['image_url']
        else:
            return super(BadgesProcessor, self).icon(msg, **config)

    def secondary_icon(self, msg, **config):<commit_msg>Check the contents in _get_user.<commit_after># This file is part of fedmsg.
# Copyright (C) 2012, 2013 Red Hat, Inc.
#
# fedmsg is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
#
# fedmsg is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with fedmsg; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# Authors:  <NAME> <<EMAIL>>
#           <NAME> <<EMAIL>>

from fasshim import gravatar_url
from fedmsg_meta_fedora_infrastructure import BaseProcessor


class BadgesProcessor(BaseProcessor):
    __name__ = "fedbadges"
    __description__ = "the Fedora Open Badges System"
    __link__ = "https://badges.fedoraproject.org/"
    __docs__ = "https://fedoraproject.org/wiki/Open_Badges"
    __obj__ = "New Badges"

    def _get_user(self, msg):
        # Handle the difference between badge.award and person.rank.advance.
        if 'user' in msg['msg']:
            return msg['msg']['user']['username']
        else:
            return msg['msg']['person']['nickname']

    def link(self, msg, **config):
        username = self._get_user(msg)
        return "https://badges.fedoraproject.org/user/%s" % username

    def subtitle(self, msg, **config):
        user = self._get_user(msg)
        if 'badge.award' in msg['topic']:
            name = msg['msg']['badge']['name']
            tmpl = self._('{user} has been awarded the "{name}" badge')
            return tmpl.format(user=user, name=name)
        else:
            rank = msg['msg']['person']['rank']
            tmpl = self._('{user} moved to position {rank} '
                          'on the badges leaderboard')
            return tmpl.format(user=user, rank=rank)

    def icon(self, msg, **config):
        if 'badge.award' in msg['topic']:
            return msg['msg']['badge']['image_url']
        else:
            return super(BadgesProcessor, self).icon(msg, **config)

    def secondary_icon(self, msg, **config):
{'fraction_non_alphanumeric': 0.11765944011786993, 'fraction_numerical': 0.008840244159124395, 'mean_word_length': 3.016906170752325, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6976230', 'n_tokens_mistral': 1418, 'n_tokens_neox': 1366, 'n_words': 482}