<commit_before>#!/usr/bin/env python

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Copyright (c) 2014 Mozilla Corporation
#
# Contributors:
# <NAME> <EMAIL>

import pyes
import json
import requests


class Elasticsearch(object):
    def __init__(self, esserver):
        """
        Class used for ES features not supported by pyes
        and for shortcuts when using pyes
        """
        self.esserver = esserver
        self.conn = pyes.ES(esserver)

    def deleteIndex(self, index):
        print('Deleting %s index...' % index)
        try:
            self.conn.indices.delete_index(index)
        except:
            pass

    def setupIndexTemplate(self, template_name, template_file):
        f = open(template_file)
        templateData = f.read()
        url = '{0}/_template/{1}'.format(self.esserver, template_name)
        r = requests.put(url=url, data=templateData)
        if r.status_code == 200:
            print('Successfully put %s template' % template_name)
        else:<commit_msg>averez-147-celery-alerts: fix dep in es.py<commit_after>#!/usr/bin/env python

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
# Copyright (c) 2014 Mozilla Corporation
#
# Contributors:
# <NAME> <EMAIL>

import pyes
import json
import requests
from datetime import datetime

class Elasticsearch(object):
    def __init__(self, esserver):
        """
        Class used for ES features not supported by pyes
        and for shortcuts when using pyes
        """
        self.esserver = esserver
        self.conn = pyes.ES(esserver)

    def deleteIndex(self, index):
        print('Deleting %s index...' % index)
        try:
            self.conn.indices.delete_index(index)
        except:
            pass

    def setupIndexTemplate(self, template_name, template_file):
        f = open(template_file)
        templateData = f.read()
        url = '{0}/_template/{1}'.format(self.esserver, template_name)
        r = requests.put(url=url, data=templateData)
        if r.status_code == 200:
            print('Successfully put %s template' % template_name)
        else:
{'fraction_non_alphanumeric': 0.1024247491638796, 'fraction_numerical': 0.012123745819397994, 'mean_word_length': 2.571641791044776, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '167676', 'n_tokens_mistral': 737, 'n_tokens_neox': 699, 'n_words': 223}