예제 #1
0
    def get_results_as_df(self, queryText, elsUrl):
        status, results, totalCount = self.get_els_results(queryText, elsUrl)

        if (status >= 300 or results == None or totalCount == 0):
            return pd.DataFrame(data=None), 0

        return util.metrics_results_to_df(results), totalCount
예제 #2
0
def getQueryString(**kwargs):
    category = kwargs["category"]
    name = kwargs['name']

    queryStatement = queryConfig.get_query_string(category, name)

    queryStringBuilder = util.QueryStringBuilder(queryStatement)
    queryString = queryStringBuilder.build(**kwargs)

    return queryString
예제 #3
0
def getQueryText(**kwargs):
    tplName = kwargs.get('tpl',
                         cfg.get_home_path() + "/template/simple_query.j2")

    queryTextBuilder = util.QueryTextBuilder(tplName)
    queryTextBuilder.size(kwargs.get('size', 1))

    queryTextBuilder.beginTime(kwargs.get('beginTime'))
    queryTextBuilder.endTime(kwargs.get('endTime'))

    queryString = kwargs.get('query', '')

    if (len(queryString) == 0):
        print("query is not specified %s" % queryString)
        logger.error("query is not specified %s" % queryString)
        exit(-1)

    queryTextBuilder.queryString(queryString)
    queryText = queryTextBuilder.build(**kwargs)

    return queryText
mswebdriverpath = parseargs.getMSWebDriverPath()
number_of_searches = parseargs.getNumSearches()
start_number = parseargs.getStartNum()

#open config.json and get user_data_dir
config_path = os.path.join('config',
                           'config-' + socket.gethostname() + '.json')
with open(config_path) as json_data_file:
    config = json.load(json_data_file)

user_data_dir = config["user.data.dir.edge"]
print("user.data.dir.edge: " + user_data_dir)

#open edge and get going!
desired_cap = {
    "args": ["userDataDir=/tmp/temp_profile"],
    "userDataDir": "/tmp/temp_profile"
}

browser = Edge(executable_path=mswebdriverpath, capabilities=desired_cap)

#go to Bing
browser.get("http://www.bing.com")

searchText = "test"

SearchUtil.runSearches(browser, searchText, number_of_searches, start_number)

browser.close()
예제 #5
0
import os
import urllib3

urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
import time
import requests
import json
import SearchConfig as cfg
import SearchUtil as util

logger = util.create_logger("search_tool", True, 10)

alertConfig = cfg.AlertConfig(cfg.get_home_path() + "/config/alert_config.yml")
queryConfig = cfg.QueryConfig(cfg.get_home_path() + "/config/query_config.yml")
envConfig = cfg.EnvConfig(cfg.get_home_path() + "/config/env_config.yml")


class SearchTool:
    def __init__(self,
                 username=os.getenv('ELS_USERNAME'),
                 password=os.getenv("ELS_PASSWORD")):
        self.username = username
        self.password = password

    def __str__(self):
        return "..."

    def query(self, queryString, elsUrl):

        logger.debug("query %s : %s begin..." % (elsUrl, queryString))
        response = requests.get(elsUrl,
예제 #6
0
import os

import SearchUtil

logger = SearchUtil.create_logger(__name__)

# refer to https://pyyaml.org/wiki/PyYAMLDocumentation
from yaml import load, dump

try:
    from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
    from yaml import Loader, Dumper


def get_home_path():
    return os.getenv("ELS_TOOL_HOME")


class YamlConfig:
    def __init__(self, yaml_file=get_home_path() + "/config/env_config.yml"):
        self.config_file = yaml_file
        self.config_data = self.read_config(yaml_file)

    def read_config(self, yaml_file):
        f = open(yaml_file, 'r', encoding='UTF-8')
        config_data = load(f)
        f.close()
        return config_data

    def get_config(self):
예제 #7
0
import SearchTool as tool
import argparse
import EmailSender
import pprint
from datetime import datetime, timedelta
import pytz

import pandas as pd
from tabulate import tabulate

pd.set_option('display.unicode.ambiguous_as_wide', True)
pd.set_option('display.unicode.east_asian_width', True)

pp = pprint.PrettyPrinter(indent=4)

logger = util.create_logger(os.path.basename("MetricsReporter"), False)


class MetricsReporter:
    def __init__(self, title="MetricsReporter", category='Potato', env='LAB'):
        self.title = title
        self.images = []
        self.csvFiles = []
        self.category = category
        self.env = env
        self.emailTemplate = cfg.get_home_path() + "/template/email_template.j2"

        self.make_report_files(title)

    def make_report_files(self, title):
        baseFileName = "./logs/{}_{}".format(self.title, FileLogger.getCurrentTimeStr('%Y%m%d%H%M%S'))