Exemplo n.º 1
0
    def __init__(self, filename=Constant.LOGGER):

        # 获取logger实例,如果参数为空则返回root logger
        self.logger = logging.getLogger(filename)

        # 指定logger输出格式
        formatter = logging.Formatter(
            '%(asctime)s %(levelname)-8s: %(message)s')

        # 文件日志
        FileUtils.make_dir(Constant.LOG_DIR)
        file_handler = logging.FileHandler("{}.log".format(
            os.path.join(Constant.LOG_DIR, filename)),
                                           encoding="utf-8")
        file_handler.setFormatter(formatter)  # 可以通过setFormatter指定输出格式

        # 控制台日志
        console_handler = logging.StreamHandler(sys.stdout)
        console_handler.formatter = formatter  # 也可以直接给formatter赋值

        # 为logger添加的日志处理器
        if file_handler.baseFilename not in \
                [x.baseFilename for x in self.logger.handlers if getattr(x, "baseFilename", False)]:
            self.logger.addHandler(file_handler)
            self.logger.addHandler(console_handler)

        # 指定日志的最低输出级别,默认为WARN级别
        self.logger.setLevel(logging.INFO)
Exemplo n.º 2
0
    def get_report(all_case, filename="result.html"):
        """运行用例,生成测试报告"""
        now = time.strftime("%Y_%m_%d_%H_%M_%S")
        FileUtils.make_dir(Constant.REPORT_DIR)
        file_path = os.path.join(Constant.REPORT_DIR, now + filename)

        fp = open(file_path, "wb")
        runner = HTMLTestRunner(stream=fp,
                                title="自动化接口测试报告,测试结果如下:",
                                description="用例执行情况")
        runner.run(all_case)
        fp.close()
Exemplo n.º 3
0
def lts_price_analysis_add(date):
    # platform_logger.info(get_log_format_string('Enter Lts_price_analysis_add'))
    print('Info: Enter Lts_price_analysis_add')
    global session
    global filter_date_str

    date_ = '-'.join([date[:4], date[4:6], date[6:8]])
    host_server_model = server_constant.get_server_model('host')
    session = host_server_model.get_db_session('common')
    if date is None or date == '':
        filter_date_str = now.strftime('%Y-%m-%d')
    else:
        filter_date_str = date_

    build_instrument_db_dict()
    get_instrument_max_id()
    data_path = os.path.join(file_path, date)

    instrument_file_list = FileUtils(data_path).filter_file(
        'HUABAO_INSTRUMENT', filter_date_str)

    # platform_logger.info('target_files: %s' % instrument_file_list)
    print('target_files: %s') % instrument_file_list
    for qd_file in instrument_file_list:
        # platform_logger.info(get_log_format_string('Start: %s' % qd_file, '-'))
        print('Start: %s') % qd_file
        read_position_file_lts(os.path.join(data_path, qd_file))
    session.commit()
    insert_server_db()

    # platform_logger.info(get_log_format_string('Exit Lts_price_analysis_add'))
    print('Exit Lts_price_analysis_add')
def ctp_price_analysis_add(date):
    # platform_logger.info(get_log_format_string('Enter ctp_price_analysis_add'))
    print('Enter ctp_price_analysis_add')
    host_server_model = server_constant.get_server_model('host')
    global session
    global session_basicinfo
    global filter_date_str
    date_ = '-'.join([date[:4], date[4:6], date[6:8]])
    session = host_server_model.get_db_session('common')
    session_basicinfo = host_server_model.get_db_session('basic_info')
    if date is None or date == '':
        filter_date_str = now.strftime('%Y-%m-%d')
    else:
        filter_date_str = date_
    data_path = os.path.join(file_path, date)
    # print data_path
    # print filter_date_str
    instrument_file_list = FileUtils(data_path).filter_file(
        'CTP_INSTRUMENT', filter_date_str)

    build_future_db_dict()
    get_instrument_max_id()
    # platform_logger.info('target_files: %s' % instrument_file_list)
    print('target_files: %s') % instrument_file_list
    for ctp_file in instrument_file_list:
        # platform_logger.info(get_log_format_string('Start: %s' % ctp_file))
        print('Start: %s') % ctp_file
        read_price_file_ctp(os.path.join(data_path, ctp_file))
    session.commit()

    insert_server_db()
    # platform_logger.info(get_log_format_string('Exit ctp_price_analysis_add'))
    print('Exit ctp_price_analysis_add')
def ctp_price_analysis(date):

    # platform_logger.info(get_log_format_string('Enter ctp_price_analysis', tag='='))
    print ('Enter ctp_price_analysis')
    host_server_model = ServerConstant().get_server_model('host')
    global session
    global filter_date_str

    date_ = '-'.join([date[:4], date[4:6], date[6:8]])
    session = host_server_model.get_db_session('common')
    if date is None or date == '':
        filter_date_str = now.strftime('%Y-%m-%d')
    else:
        filter_date_str = date_


    data_path = os.path.join(file_path, date)
    instrument_file_list = FileUtils(data_path).filter_file('CTP_INSTRUMENT', filter_date_str)
    print instrument_file_list
    market_file_list = FileUtils(data_path).filter_file('CTP_MARKET',
                                                         filter_date_str)
    ctp_file_list = []
    ctp_file_list.extend(instrument_file_list)
    ctp_file_list.extend(market_file_list)
    # platform_logger.info('src_file_path: %s' % data_path)
    print ('src_file_path: %s')% data_path
    # platform_logger.info('target_file_list: %s')% ctp_file_list
    print ('target_file_list: %s') % ctp_file_list

    for ctp_file in ctp_file_list:
        # platform_logger.info(get_log_format_string('start: %s' % ctp_file, tag='-'))
        print ('start: %s')% ctp_file
        read_price_file_ctp(os.path.join(data_path, ctp_file))

    set_main_submain()
    update_db()
    session.commit()
    # platform_logger.info(get_log_format_string('Exit ctp_price_analysis', tag='='))
    print ('Exit ctp_price_analysis')
def lts_price_analysis(date):
    # platform_logger.info(get_log_format_string('Enter Lts_price_analysis'))
    print('Enter Lts_price_analysis')
    global session
    global filter_date_str
    date_ = '-'.join([date[:4], date[4:6], date[6:8]])

    host_server_model = ServerConstant().get_server_model('host')
    session = host_server_model.get_db_session('common')
    if date is None or date == '':
        filter_date_str = now.strftime('%Y-%m-%d')
    else:
        filter_date_str = date_

    build_instrument_db_dict()
    data_path = os.path.join(file_path, date)
    instrument_file_list = FileUtils(data_path).filter_file('HUABAO_INSTRUMENT', filter_date_str)
    market_file_list = FileUtils(data_path).filter_file('HUABAO_MARKET', filter_date_str)

    lts_file_list = []
    lts_file_list.extend(instrument_file_list)
    lts_file_list.extend(market_file_list)
    # platform_logger.info('taget_files: %s' % lts_file_list)
    print ('Info: taget_files: %s') % lts_file_list

    for qd_file in lts_file_list:
        # platform_logger.info(get_log_format_string('Start: %s' % qd_file))
        print ('Info: Start: %s') % qd_file
        read_position_file_lts(os.path.join(data_path, qd_file))

    # platform_logger.info('update_structured_fund')
    print ('Info: update_structured_fund')

    update_structured_fund()
    update_db()
    session.commit()
    # platform_logger.info(get_log_format_string('Exit Lts_price_analysis'))
    print('Info: Exit Lts_price_analysis')
def __account_position_enter(add_flag):
    print 'Enter XT_position_analysis add_account_position.'
    host_server_model = ServerConstant().get_server_model('host')
    global session_portfolio, session_om
    session_portfolio = host_server_model.get_db_session('portfolio')
    session_om = host_server_model.get_db_session('om')

    xt_position_file_list = FileUtils(file_path).filter_file(
        'PROXYXH_POSITION', now_date_str)
    for xt_file in xt_position_file_list:
        read_position_file_xt('%s/%s' % (file_path, xt_file), add_flag)

    session_portfolio.commit()
    session_om.commit()
    print 'Exit XT_position_analysis add_account_position.'
            symbol = 'SSE50'

        if symbol in open_trade_dict:
            open_trade_dict[symbol] += abs(int(trade_db.qty))
        else:
            open_trade_dict[symbol] = abs(int(trade_db.qty))
    for (symbol, today_open) in open_trade_dict.items():
        update_sql = "update portfolio.account_trade_restrictions set TODAY_OPEN = %s where \
                TICKER = '%s' and ACCOUNT_ID = %s" % (today_open, symbol,
                                                      account_id)
        session_portfolio.execute(update_sql)


if __name__ == '__main__':
    print 'Enter ts_position_analysis.'
    host_server_model = ServerConstant().get_server_model('host')
    session_common = host_server_model.get_db_session('common')
    session_portfolio = host_server_model.get_db_session('portfolio')
    session_om = host_server_model.get_db_session('om')

    __build_ticker_exchange(host_server_model)
    ts_position_file_list = FileUtils(file_path).filter_file(
        'ysorder', now_date_str)
    for ts_file in ts_position_file_list:
        read_position_file_ts('%s/%s' % (file_path, ts_file))

    session_common.commit()
    session_portfolio.commit()
    session_om.commit()
    print 'Exit ts_position_analysis.'
Exemplo n.º 9
0
import sys
import os
from tools.file_utils import FileUtils

with open(
        FileUtils.get_current_file_path(__file__) + os.path.sep + 'temp.conf',
        'w') as temp_conf:
    temp_conf.write("ENV=" + sys.argv[1])
Exemplo n.º 10
0
        # productID = getattr(messageInfo, 'ProductID', '')


def update_db():
    for (dict_key, future) in future_db_dict.items():
        session.merge(future)


def build_future_db_dict():
    query = session.query(Instrument)
    for future in query.filter(Instrument.exchange_id == 25):
        dict_key = '%s|%s' % (future.ticker, future.exchange_id)
        future_db_dict[dict_key] = future


if __name__ == '__main__':
    print 'Enter femas_price_analysis.'
    host_server_model = ServerConstant().get_server_model('host')
    session = host_server_model.get_db_session('common')
    build_future_db_dict()
    femas_td_file_list = FileUtils(file_path).filter_file('Femas_TD', today_str)
    for femas_td_file in femas_td_file_list:
        read_price_file_femas('%s/%s' % (file_path, femas_td_file))

    # femas_md_file_list = FileUtils(file_path).filter_file('Femas_MD', today_str)
    # for femas_md_file in femas_md_file_list:
    #     read_price_file_femas('%s/%s' % (file_path, femas_md_file))
    update_db()
    session.commit()
    print 'Exit femas_price_analysis.'
Exemplo n.º 11
0
def screenshot(driver, filename):
    """截屏"""
    FileUtils.make_dir(Constant.SCREEN_SHOT_DIR)
    filepath = os.path.join(Constant.SCREEN_SHOT_DIR, filename)
    print(filepath)
    driver.get_screenshot_as_file(filepath)
            position_db.purchase_avail = purchase_avail
            position_db.frozen = long_frozen
            position_db.update_date = datetime.now()
            position_list.append(position_db)


def update_db():
    for order_db in order_list:
        session_om.add(order_db)
    for trade_db in trade_list:
        session_om.add(trade_db)
    for position_db in position_list:
        session_portfolio.add(position_db)


if __name__ == '__main__':
    print 'Enter Lts_position_analysis.'
    host_server_model = ServerConstant().get_server_model('host')
    session_portfolio = host_server_model.get_db_session('portfolio')
    session_om = host_server_model.get_db_session('om')

    lts_position_file_list = FileUtils(file_path).filter_file(
        'HUABAO_POSITION', today_str)
    for lts_file in lts_position_file_list:
        read_position_file_lts('%s/%s' % (file_path, lts_file))

    update_db()
    session_portfolio.commit()
    session_om.commit()
    print 'Exit Lts_position_analysis.'
        elif 'IH' in symbol:
            symbol = 'SSE50'

        if symbol in open_trade_dict:
            open_trade_dict[symbol] += abs(int(trade_db.qty))
        else:
            open_trade_dict[symbol] = abs(int(trade_db.qty))
    for (symbol, today_open) in open_trade_dict.items():
        update_sql = "update portfolio.account_trade_restrictions set TODAY_OPEN = %s where \
                TICKER = '%s' and ACCOUNT_ID = %s" % (today_open, symbol, account_id)
        session_portfolio.execute(update_sql)


if __name__ == '__main__':
    print 'Enter ctp_position_analysis.'
    host_server_model = ServerConstant().get_server_model('host')
    session_common = host_server_model.get_db_session('common')
    session_portfolio = host_server_model.get_db_session('portfolio')
    session_om = host_server_model.get_db_session('om')

    update_sql = "update portfolio.account_trade_restrictions set TODAY_OPEN = 0, TODAY_CANCEL=0 where 1=1"
    session_portfolio.execute(update_sql)

    ctp_position_file_list = FileUtils(file_path).filter_file('CTP_POSITION', now_date_str)
    for ctp_file in ctp_position_file_list:
        read_position_file_ctp('%s/%s' % (file_path, ctp_file))

    session_common.commit()
    session_portfolio.commit()
    session_om.commit()
    print 'Exit ctp_position_analysis.'

def update_db():
    for order_db in order_list:
        session_om.add(order_db)
    for trade_db in trade_list:
        session_om.add(trade_db)
    for position_db in position_list:
        session_portfolio.add(position_db)


def update_position_prev_net(account_id):
    update_sql = "Update portfolio.account_position Set PREV_NET = YD_POSITION_LONG - YD_POSITION_SHORT where ID=%s \
and DATE='%s' and symbol != 'CNY'" % (account_id, today_str)
    session_portfolio.execute(update_sql)


if __name__ == '__main__':
    print 'Enter femas_position_analysis.'
    host_server_model = ServerConstant().get_server_model('host')
    session_portfolio = host_server_model.get_db_session('portfolio')
    session_om = host_server_model.get_db_session('om')

    femas_position_file_list = FileUtils(file_path).filter_file('FEMAS_POSITION', today_str)
    for femas_file in femas_position_file_list:
        read_position_file_femas('%s/%s' % (file_path, femas_file))

    session_portfolio.commit()
    session_om.commit()
    print 'Exit femas_position_analysis.'
Exemplo n.º 15
0
import os

from tools.property_utils import PropertyUtils
from tools.file_utils import FileUtils
from settings.environment import Environment, UAT_Account, QA_Account, STG_Account

property_utils = PropertyUtils(FileUtils.get_current_file_path(__file__) + os.path.sep + "temp.conf")
environment = property_utils.get_property_value("ENV")

if environment == '':
    environment = Environment.UAT

environment = Environment.UAT

DOMAIN = "http://%s.englishtown.com" % environment
COMMON_LOGIN_URL =  DOMAIN + "/login.aspx?ctr=us"
COOKIE_LOGIN_URL = DOMAIN + "/login/handler.ashx"
MY_BOOKINGS_PAGE_URL = DOMAIN + "/school/evc/pl"
PL_TIME_SLOTS_URL = "http://%s.englishtown.com/school/evc/pl/slots" % environment
PL_TIME_SLOTS = {'TimeZone_id':'Eastern Standard Time', 'SubserviceType':'', 'HasBilingual':'true',\
        'Gender':'', 'BaseDate':'', 'DayOffset':'0', 'DayCount':'7'}
AVAILABLE_PL_URL = "http://%s.englishtown.com/school/evc/pl/available" % environment
BOOKED_PL_URL = "http://%s.englishtown.com/school/evc/pl/booked" % environment
STUDENT_CONTEXT_QUERY_STRING_URL = \
    "http://%s.englishtown.com/services/shared/queryproxy?c=countrycode=cn|culturecode=en|partnercode=Corp|siteversion=development" \
    % environment
PL_BOOK_URL = "http://%s.englishtown.com/school/evc/pl/book" % environment
PL_UPDATE_TOPIC_URL = "http://%s.englishtown.com/school/evc/pl/updatetopic" % environment
STUDENT_CONTEXT_QUERY_STRING = {'q':'evc_context!current|evc_studentcourse!current'}
MAXIMUM_ALLOWED_CLASSES_NUMBER = 4