Пример #1
0
def clean_browser_data():
    debug.file_name = 'clean_browser_data.log'
    log = debug.create_log()
    log.setLevel(20)
    from kairos import tools
    config = tools.get_config()
    log.setLevel(config.getint('logging', 'level'))

    driver_type = 'chromedriver'
    driver_count = sum(1 for process in psutil.process_iter()
                       if process.name().startswith(driver_type))

    if config.has_option('webdriver', 'user_data_directory'):
        user_data_directory = config.get('webdriver', 'user_data_directory')
        user_data_base_dir, tail = os.path.split(user_data_directory)
        with os.scandir(user_data_base_dir) as user_data_directories:
            for entry in user_data_directories:
                # remove all directories that start with 'kairos_' followed by a number
                path = os.path.join(user_data_base_dir, entry)
                if (entry.name.startswith('kairos_') and not tools.path_in_use(
                        path, log)) or (entry.name.startswith('kairos')
                                        and driver_count == 0):
                    if entry.name != user_data_directory:
                        try:
                            shutil.rmtree(path)
                            log.info("{} removed".format(entry.name))
                        except Exception as e:
                            log.exception(e)
                elif entry.name.startswith('kairos_'):
                    log.info(
                        "{} is in use and cannot be removed (close all instances of {} and try again)"
                        .format(entry.name, driver_type))
        log.info("cleaning complete")
    else:
        log.info("skipping. User data directory is not set in kairos.cfg")
Пример #2
0
def sort_back_test_data(filename, sort_by, reverse=True):
    from kairos import tools
    from tv import tv

    debug.file_name = 'sort_back_test_data.log'
    log = debug.create_log()
    log.setLevel(20)
    config = tools.get_config()
    log.setLevel(config.getint('logging', 'level'))
    # log.info("{} {} {}".format(filename, sort_by, reverse))

    path = os.path.join(os.path.curdir, filename)
    if os.path.exists(path):
        try:
            import json
            with open(path, 'r') as stream:
                data = json.load(stream)
                data = tv.back_test_sort(data, sort_by, reverse)
            with open(path, 'w') as stream:
                stream.write(json.dumps(data, indent=4))
        except Exception as e:
            log.exception(e)
    else:
        log.error("{} doesn't exist".format(filename))
        exit(1)
Пример #3
0
def test_mongodb():
    # set log name before importing... the import creates the log whatever it's file name
    debug.file_name = 'test_mongodb.log'
    log = debug.create_log()
    log.setLevel(20)
    from kairos import tools
    config = tools.get_config()
    log.setLevel(config.getint('logging', 'level'))

    connection_string = config.get('mongodb', 'connection_string')
    collection = config.get('mongodb', 'collection')

    from kairos import mongodb
    mongodb.test(connection_string, collection, log)
    exit(0)
Пример #4
0
from kairos import tools
from tv import tv

# -------------------------------------------------
#
# Utility to read email from Gmail Using Python
#
# ------------------------------------------------

BASE_DIR = r"" + os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
CURRENT_DIR = os.path.curdir

log = tools.log
log.setLevel(20)
config = tools.get_config(CURRENT_DIR)
log.setLevel(config.getint('logging', 'level'))

uid = str(config.get('mail', 'uid'))
pwd = str(config.get('mail', 'pwd'))
imap_server = config.get("mail", "imap_server")
imap_port = 993
smtp_server = config.get("mail", "smtp_server")
smtp_port = 465

charts = dict()


def create_browser(run_in_background=True):
    return tv.create_browser(run_in_background)
Пример #5
0
from kairos import tools
from kairos import mongodb
from tv import tv
import http.client as http_client
# -------------------------------------------------
#
# Utility to read email from Gmail Using Python
#
# ------------------------------------------------

TEST = False
BASE_DIR = r"" + os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
CURRENT_DIR = os.path.curdir

config = tools.get_config()
log = tools.create_log()
log.setLevel(20)
log.setLevel(config.getint('logging', 'level'))

uid = str(config.get('mail', 'uid'))
pwd = str(config.get('mail', 'pwd'))
imap_server = config.get("mail", "imap_server")
imap_port = 993
smtp_server = config.get("mail", "smtp_server")
smtp_port = 465

charts = dict()


def create_browser(run_in_background=True):