def main(targetYear=None, targetMonth=None):
    print('Watching List data caculate main start!')
    file_name = os.path.join(setting.get_root_dir(), excel_file_name)
    workbook = openpyxl.load_workbook(file_name, data_only=True)
    sheet = workbook[sheet_name_Watching_Input]
    record_list = []
    symbols_corr_list = []

    ft.clean_target_dir(os.path.join(setting.get_watching_list_file_dir()))
    for i in range(4, sheet.max_row + 1, 1):

        record = WatchingRecord()
        code1 = str(sheet.cell(row=i, column=3).value)
        code2 = str(sheet.cell(row=i, column=7).value)
        if (code1 is None or code2 is None):
            continue
        record.code1 = code1
        record.code2 = code2
        record_list.append(record)

    for record in record_list:
        symb1 = record.code1
        symb2 = record.code2

        if (symb1 is None or symb2 is None or len(symb1) <= 0
                or len(symb2) <= 0 or symb1 == "None" or symb2 == "None"):
            continue

        _pairs = pairs_main.create_pairs_dataframe(
            setting.get_input_data_dir(), symb1, symb2)
        corr_3m, corr_1y = trade_util.check_corr(_pairs, symb1, symb2)
        coint_3m, coint_1y = trade_util.check_cointegration(
            _pairs, symb1, symb2)
        symbols_corr_list.append(
            [symb1, symb2, corr_3m, corr_1y, coint_3m, coint_1y])
        _pairs = _pairs.sort_values('DATE', ascending=True)
        _pairs = pairs_main.calculate_spread_zscore(_pairs, symb1, symb2)
        _pairs = _pairs.sort_values('DATE', ascending=False)
        file_util.write_csv(
            _pairs,
            os.path.join(setting.get_watching_list_file_dir(),
                         symb1 + '_' + symb2 + '.csv'))

    corr_data = sorted(symbols_corr_list, key=itemgetter(3),
                       reverse=True)  # sort by 3 month corr
    corr_data = pd.DataFrame(columns=[
        'SYM_A', 'SYM_B', 'CORR_3M', 'CORR_1Y', 'COINT_3M', 'COINT_1Y'
    ],
                             data=corr_data)
    # file_util.write_csv(corr_data, os.path.join(setting.get_result_dir(), corr_result_file_name))

    pairs_main.output_report(corr_data, False,
                             setting.get_watching_list_file_dir(),
                             setting.watching_corr_result_file_name)

    print('Watching List data caculate main end!')
# -*- coding: utf_8 -*-

import io
import re
import hashlib
import tempfile
import shutil
import json
from urllib import request
from urllib import parse

import setting
from VulnerabilityAnalyzer import java_scan

root_dir = setting.get_root_dir()
org_list = root_dir + 'VulnerabilityAnalyzer/malware_domain_list.csv'


def update_domain_list():
    try:
        url = "https://www.malwaredomainlist.com/mdlcsv.php"
        response = request.urlopen(url)
        data = response.read()
        tmp_file = tempfile.NamedTemporaryFile()
        tmp_file.write(data)

        if hashlib.md5(org_list.encode('utf-8')) != hashlib.md5(tmp_file.name.encode('utf-8')):
            print("恶意url和ip库需要更新")
            rd = io.open(tmp_file.name, mode='r', encoding='utf-8', errors='ignore')
            line = rd.readline()
            rd.close()
def main(targetYear=None, targetMonth=None):
    print('Dry Run Positin / History Aalysis main start!')
    file_name = os.path.join(setting.get_root_dir(), excel_file_name)
    workbook = openpyxl.load_workbook(file_name, data_only=True)
    sheet = workbook[sheet_name_history]
    record_list = []

    ft.clean_target_dir(setting.get_dryrun_trade_open_dir())
    for i in range(4, sheet.max_row + 1, 2):
        record = TradeRecord()
        year = sheet.cell(row=i, column=27).value
        if (year is None):
            continue
        record.year = str(year)
        record.month = str(sheet.cell(row=i, column=28).value)
        record.sellCode = str(sheet.cell(row=i, column=6).value)
        record.buyCode = str(sheet.cell(row=i + 1, column=6).value)
        record_list.append(record)

    open_position_sheet = workbook[sheet_name_open_position]
    for i in range(4, open_position_sheet.max_row + 1, 2):

        if (open_position_sheet.cell(row=i, column=6).value is None):
            break

        record = TradeRecord()
        record.sellCode = str(open_position_sheet.cell(row=i, column=6).value)
        record.buyCode = str(
            open_position_sheet.cell(row=i + 1, column=6).value)
        record.kbn = 'open'
        record_list.append(record)

    for record in record_list:
        symb1 = record.sellCode
        symb2 = record.buyCode
        if record.sellCode > record.buyCode:
            symb1 = record.buyCode
            symb2 = record.sellCode
        file_name = symb1 + '_' + symb2 + '.csv'

        if (record.kbn != 'open'):
            target_ymd = datetime.datetime(year=int(record.year),
                                           month=int(record.month),
                                           day=1)
            ymd_edit = target_ymd + relativedelta(months=2)
            if (datetime.datetime.now() > ymd_edit):
                continue

        if (record.kbn == 'open'):
            ft.create_target_dir(
                os.path.join(setting.get_dryrun_trade_dir(), record.kbn))
            csv_file_full_path = os.path.join(setting.get_dryrun_trade_dir(),
                                              record.kbn, file_name)
        else:
            ft.create_target_dir(
                os.path.join(setting.get_dryrun_trade_history_dir(),
                             record.year))
            ft.create_target_dir(
                os.path.join(setting.get_dryrun_trade_history_dir(),
                             record.year, record.month))
            csv_file_full_path = os.path.join(
                setting.get_dryrun_trade_history_dir(), record.year,
                record.month, file_name)

        cacluate_needed_data(symb1, symb2, csv_file_full_path)

    print('Dry Run Positin / History Aalysis main end!')