<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
    blockstack-profiles-py
    ~~~~~
    copyright: (c) 2014-2015 by Halfmoon Labs, Inc.
    copyright: (c) 2016 by Blockstack.org

    This file is part of blockstack-profiles-py

    Blockstack-profiles-py is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Blockstack-profiles-py 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 General Public License for more details.
    You should have received a copy of the GNU General Public License
    along with blockstack-profiles-py.  If not, see <http://www.gnu.org/licenses/>.
"""

import json


def is_profile_in_legacy_format(profile):
    """
    Is a given profile JSON object in legacy format?
    """
    if isinstance(profile, dict):
        pass
    elif isinstance(profile, (str, unicode)):
        try:
            profile = json.loads(profile)
        except ValueError:
            return False
    else:
        return False

    if profile.has_key("@type"):
        return False

    if profile.has_key("@context"):
        return False

    is_in_legacy_format = False

    if profile.has_key("avatar"):
        is_in_legacy_format = True
    elif profile.has_key("cover"):
        is_in_legacy_format = True
    elif profile.has_key("bio"):
        is_in_legacy_format = True
    elif profile.has_key("twitter"):
        is_in_legacy_format = True
    elif profile.has_key("facebook"):
        is_in_legacy_format = True

    return is_in_legacy_format


def format_account(service_name, data):
    """
    Given profile data and the name of a
    social media service, format it for
    the zone file.

    @serviceName: name of the service
    @data: legacy profile verification<commit_msg>changes to using in because has_key() gives exceptions on certain malformed profiles (and is generally deprecated)<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
    blockstack-profiles-py
    ~~~~~
    copyright: (c) 2014-2015 by Halfmoon Labs, Inc.
    copyright: (c) 2016 by Blockstack.org

    This file is part of blockstack-profiles-py

    Blockstack-profiles-py is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Blockstack-profiles-py 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 General Public License for more details.
    You should have received a copy of the GNU General Public License
    along with blockstack-profiles-py.  If not, see <http://www.gnu.org/licenses/>.
"""

import json


def is_profile_in_legacy_format(profile):
    """
    Is a given profile JSON object in legacy format?
    """
    if isinstance(profile, dict):
        pass
    elif isinstance(profile, (str, unicode)):
        try:
            profile = json.loads(profile)
        except ValueError:
            return False
    else:
        return False

    if "@type" in profile:
        return False

    if "@context" in profile:
        return False

    is_in_legacy_format = False

    if "avatar" in profile:
        is_in_legacy_format = True
    elif "cover" in profile:
        is_in_legacy_format = True
    elif "bio" in profile:
        is_in_legacy_format = True
    elif "twitter" in profile:
        is_in_legacy_format = True
    elif "facebook" in profile:
        is_in_legacy_format = True

    return is_in_legacy_format


def format_account(service_name, data):
    """
    Given profile data and the name of a
    social media service, format it for
    the zone file.

    @serviceName: name of the service
    @data: legacy profile verification
{'fraction_non_alphanumeric': 0.07367410607151428, 'fraction_numerical': 0.00671946244300456, 'mean_word_length': 2.785649409627611, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5546630', 'n_tokens_mistral': 1199, 'n_tokens_neox': 1155, 'n_words': 448}