Ejemplo n.º 1
0
def do_one_flow(driver, path):
    try:
        with open(path, encoding='utf-8') as f:
            filename = f.name
        logger.info(Messages.Start_Flow % filename)
        open_file(driver, path, do_flow)
        logger.info(Messages.End_Flow % filename)
    except Exception as e:
        logger.error(Messages.Flow_Handle_Failed % e)
Ejemplo n.º 2
0
    def __process_pgn_list(self, file_list, output_file=None):
        """
        This takes a PGN file and creates two output files
        1. First file contains the game information
        2. Second file containing the moves
        """

        log.info("Starting process..")

        result = Result.get_empty_result()

        file_name_games = output_file + '_game_info.csv'
        file_name_moves = output_file + '_moves.csv'

        file_games = open_file(file_name_games)
        file_moves = open_file(file_name_moves)

        if file_games is None or file_moves is None:
            log.info("No data exported!")
            return result

        add_headers = True
        for file in file_list:
            process = Process(file, file_games, file_moves, self._engine_path,
                              self._depth)
            process.parse_file(add_headers)
            add_headers = False

        file_games.close()
        file_moves.close()

        # return a result object to indicate outcome
        result = self.__get_result_of_output_files(file_name_games,
                                                   file_name_moves)

        log.info("ending process..")
        return result
Ejemplo n.º 3
0
font_name = font_manager.FontProperties(fname="c:/Windows/Fonts/malgun.ttf").get_name()
rc('font', family=font_name)
import os
import numpy as np
import collections as clt
import pandas as pd
import random as rd

# Step 2. 경마정보조회를 위한 요청변수 및 요청주소 등을 구성합니다.
# Step 2-1. Looging을 위하여 공통 모듈에서 로거를 정의합니다.
f = cm.pre_logging() # 등록마 조회 결과 파일을 로딩

# Step 2-2. '4-1'에서 저장한 파일을 이용하여 해당 데이터를 로딩합니다.
c = []
fn = os.getcwd() + '/data/' + 'RegisteredHorse.da' # url = 'http://data.kra.co.kr/publicdata/service/hrReg/getHrReg' # 등록마 조회 (meet)
c.append(cm.open_file(fn, True))
cm.logF(f, c)

# Step 3. item의 구조를 분석하고, 분석하고자 하는 값들을 추출하기 위한 데이터를 전처리합니다.
pp = pp.PrettyPrinter(indent=4)
data = []
for i in range(0, len(c)):
    try:
        # 응답값이 XML일 경우
        _djson = cm.x2j(c[i])
        item = _djson['response']['body']['items']['item']

        # pp.pprint(item)
        cm.logF(f, item)
        if (isinstance(item, dict)):
            data.append(item)
Ejemplo n.º 4
0
def do_flow(driver, flowdata):
    if flowdata:
        # 获取流程节点类型
        t = flowdata.get(FlowNodeProp.Type.value)
        # 流程-打开目标网址
        if t == FlowNodeType.Open.value:
            param = flowdata.get(FlowNodeProp.Params.value)
            if param:
                target_url = param
            else:
                # 获取目标网站网址
                target_url = get_item(flowdata, FlowNodeProp.TargetURL.value)
            # 如果存在常量值执行替换
            target_url = const.get_const_val(target_url)
            driver.get(target_url)
        # 流程-处理读取数据文件
        elif t == FlowNodeType.Read.value:
            # 读取方式
            findmethod = get_item(flowdata, FlowNodeProp.FindMethod.value)
            # 读取文件路径
            target_url = get_item(flowdata, FlowNodeProp.TargetURL.value)
            # 读取数据文件
            with open(target_url, encoding='utf-8') as f:
                mock_data = json.load(f)
            # 根据数据文件,页面自动赋值
            if mock_data:
                # 获取常量值
                mock_data = const.repalce_const_val(mock_data)
                recursive_set_data(driver, By.__dict__[findmethod], mock_data)
        # 流程-处理单击
        elif t == FlowNodeType.Click.value or t == FlowNodeType.DbClick.value:
            handle_click(driver, flowdata, t)
        # 流程-处理弹出框
        elif t == FlowNodeType.Alert.value:
            # 等待弹出框出现
            wait = WebDriverWait(driver, 10)
            wait.until(EC.alert_is_present())
            # 获取弹出框
            alert = driver.switch_to.alert
            # 弹出框确认(默认执行弹出框确认操作)
            alert.accept()
        # 流程-剪切板操作(复制)
        elif t == FlowNodeType.Copy.value:
            if flowdata.get(FlowNodeProp.FindMethod.value) != None:
                # 获取目标元素
                element = get_element_by_flow(driver, flowdata)
                if element.text:
                    copy_val = element.text
                elif element.get_attribute('value'):
                    copy_val = element.get_attribute('value')
            else:
                # 如果存在常量值优先替换
                flowdata = repalce_const_val(flowdata)
                flowdata = repalce_dynamic_val(flowdata)
                copy_val = get_item(flowdata, FlowNodeProp.ItemVal.value)
            # 复制到ClipBoard
            pyperclip.copy(copy_val)
        # 流程-剪切板操作(粘贴)
        elif t == FlowNodeType.Paste.value:
            # 获取目标元素
            element = get_element_by_flow(driver, flowdata)
            # 复制到ClipBoard
            setval = pyperclip.paste()
            if setval:
                element.clear()
                # 首选使用常量值
                val = const.get_const_val(setval)
                element.send_keys(val)
        # 流程-添加缓存值
        elif t == FlowNodeType.Cache.value:
            # 获取想要设置的缓存值
            val = get_item(flowdata, FlowNodeProp.ItemVal.value)
            if isinstance(val, str):
                # 首选使用常量值
                val = const.get_const_val(val)
                setval = val
            elif isinstance(val, object):
                setval = json.dumps(val)
            # 获取缓存键
            cachekey = get_item(flowdata, FlowNodeProp.CacheKey.value)
            # 添加浏览器缓存
            driver.add_cookie({'name': cachekey, 'value': setval})
        # 流程-画面要素設定
        elif t == FlowNodeType.SetVal.value:
            # 如果存在常量值优先替换
            flowdata = repalce_const_val(flowdata)
            # 获取动态生成的项目設定値
            flowdata = repalce_dynamic_val(flowdata)
            # 目标元素
            target = get_item(flowdata, FlowNodeProp.Target.value)
            # 获取目标元素方式
            findmethod = get_item(flowdata, FlowNodeProp.FindMethod.value)
            # 获取动态生成的项目設定値
            itemval = get_item(flowdata, FlowNodeProp.ItemVal.value)
            # 指定元素设置缓存值
            set_element_val(driver, By.__dict__[findmethod], itemval, target)
        # 流程-循环操作
        elif t == FlowNodeType.For.value:
            # 子操作流程节点集合
            child_flows = get_item(flowdata, FlowNodeProp.Flow.value)
            if FlowNodeProp.StartIdx.value in flowdata and FlowNodeProp.EndIdx.value in flowdata:
                # 开始索引
                startIdx = get_item(flowdata, FlowNodeProp.StartIdx.value)
                # 结束索引
                endIdx = get_item(flowdata, FlowNodeProp.EndIdx.value)
                # 循环指定索引范围
                for idx in range(int(startIdx), int(endIdx) + 1):
                    handle_for_childflow(driver, child_flows, idx)
            elif FlowNodeProp.TargetURL.value in flowdata:
                # 读取文件路径
                target_url = get_item(flowdata, FlowNodeProp.TargetURL.value)
                with open(target_url) as csvfile:
                    for row in csv.reader(csvfile):
                        handle_for_childflow(driver, child_flows, row[0])
            else:
                # 获取目标元素列表
                elements = get_elements_by_flow(driver, flowdata)
                # 循环处理元素列表
                for element in elements:
                    handle_for_childflow(driver, child_flows, element)
        # 流程-加载既存流程文件
        elif t == FlowNodeType.FlowFile.value:
            # 读取文件路径
            file_url = get_item(flowdata, FlowNodeProp.TargetURL.value)
            param = flowdata.get(FlowNodeProp.Params.value)
            open_file(driver, file_url, do_flow, param)
        # 流程-鼠标键盘操作
        elif t == FlowNodeType.KeyBoard.value:
            # 读取鼠标键盘操作
            itemval = get_item(flowdata, FlowNodeProp.ItemVal.value)
            # 获取操作次数
            count = flowdata.get(FlowNodeProp.Count.value, 1)
            source = None
            if FlowNodeProp.Target.value in flowdata and FlowNodeProp.FindMethod.value in flowdata:
                # 读取指定元素
                source = get_element_by_flow(driver, flowdata)
            else:
                source = driver
            for i in range(count):
                source.send_keys(Keys.__dict__[itemval])
                # ActionChains(source).send_keys(Keys.__dict__[itemval]).perform()
        # 获取节点可选操作配置
        option = flowdata.get(FlowNodeProp.Option.value)
        if option:
            # 处理可选操作
            handle_option(driver, option)