def test_compare_other(env, stock_market, stock_code, stock_type, queue, log_file): youyu_result = youyu.parser_yff_basic(env, stock_market, stock_code, stock_type) sina_result = sina.parser_sina_basic(stock_market, stock_code) futu_result = futu.parser_futu_basic(stock_market, stock_code) util.add_message_file( log_file, "[%s]Market: %s Code: %s Response:%s" % (util.get_time(datetime.datetime.now()), stock_market, stock_code, str(youyu_result))) data = [] fail_item = [] for item in basicConfig.compare_other_data: youyu_num = str(youyu_result[item]) sina_num = str(sina_result[item]) futu_num = str(futu_result[item]) if util.check_error_code(sina_num) and util.check_error_code(futu_num): data.append( [item, youyu_num, sina_num, futu_num, basicConfig.test_skip]) elif sina_num == "None" and util.check_error_code(futu_num): data.append( [item, youyu_num, sina_num, futu_num, basicConfig.test_skip]) else: # ------------------------ 异常数据处理 ------------------------ # 处理 -- if youyu_result[item] == "--": sina_num = "--" futu_num = "--" # 处理不带单位的情况下,保留位数不一致,统一向有鱼股票看齐 if util.check_not_contain_chinese(youyu_num): sina_num = util.decimal_format(youyu_num, sina_num) futu_num = util.decimal_format(youyu_num, futu_num) # --------------------------- 结束 ---------------------------- if youyu_num == sina_num or youyu_num == futu_num: data.append([ item, youyu_num, sina_num, futu_num, basicConfig.test_pass ]) else: fail_item.append(item) data.append([ item, youyu_num, sina_num, futu_num, basicConfig.test_fail ]) queue.put({ "stock_market": stock_market, "stock_code": stock_code, "stock_type": stock_type, "result": util.test_result(data), "fail_item": fail_item, "data": data }) return data
def parser_tencent_financial(stock_market, stock_code): response = tencent.tencent_financial(stock_market, stock_code) data = {} for key in basicConfig.finance_hk: data.setdefault(key, "0.00") compare_data = basicConfig.finance_hk if util.check_error_code(response.get("code")): for item in compare_data: data[item] = basicConfig.ResponseError.get("code") else: try: temp = response.get("data") first = temp[0] second = temp[1] third = temp[2] data[u"流动资产"] = first[1][1][0] data[u"流动负债"] = first[2][1][0] data[u"总资产"] = first[3][1][0] data[u"总负债"] = first[4][1][0] data[u"营业额"] = second[1][1][0] data[u"经营活动现金流量"] = third[1][1][0] data[u"投资活动现金流量"] = third[2][1][0] data[u"融资活动现金流量"] = third[3][1][0] except: for item in compare_data: data[item] = basicConfig.ParserError.get("data") return data
def parser_yff_basic(env, stock_market, stock_code, stock_type): yff = youyu.yff_basic(env, stock_market, stock_code, stock_type) data = {} for key in basicConfig.compare_other_data: data.setdefault(key, "0.00") compare_data = basicConfig.compare_other_data if util.check_error_code(yff.get("code")): for item in compare_data: data[item] = basicConfig.ResponseError.get("data") else: try: yff_result = yff.get("data").get("datagrid") for item in yff_result: data[item.get("k")] = item.get("v") yff_result_price = yff.get("data").get("price") check_list = [["1", u"最新价"], ["6", u"涨跌额"], ["7", u"涨跌率"]] for check in check_list: data[check[1]] = yff_result_price.get(check[0]) check_list = [["3", u"今开"], ["2", u"昨收"], ["4", u"最高"], ["5", u"最低"]] yff_result_temp = yff.get("data") for check in check_list: data[check[1]] = yff_result_temp.get(check[0]) except: for item in compare_data: data[item] = basicConfig.ParserError.get("data") return data
def futu_basic(stock_market, stock_code): stock_code = change_abnormal_stock(stock_code) date = str(time.time()).replace(".", "0") response_data = get_security_id(stock_market, stock_code) if util.check_error_code(response_data["code"]): result = response_data else: url = "http://www.futunn.com/trade/quote-basic?security_id=%s&_=%s" % ( response_data.get("code"), date) result = basicRequest.request_get(url) return result
def test_compare_finance(env, stock_market, stock_code, stock_type, queue, log_file): youyu_result = youyu.parser_yff_finance(env, stock_market, stock_code) tencent_result = tencent.parser_tencent_financial(stock_market, stock_code) util.add_message_file( log_file, "[%s]Market: %s Code: %s Response:%s" % (util.get_time(datetime.datetime.now()), stock_market, stock_code, str(youyu_result))) data = [] for item in basicConfig.finance_hk: youyu_num = str(youyu_result[item]) tencent_num = str(tencent_result[item]) # ------------------------ 异常数据处理 ------------------------ # 处理 自选股中带 , if "," in tencent_num: tencent_num = tencent_num.replace(",", "") # --------------------------- 结束 ---------------------------- if util.check_error_code(youyu_num) \ or util.check_error_code(tencent_num) \ or tencent_num == "0.00": data.append([item, youyu_num, tencent_num, basicConfig.test_skip]) else: if youyu_num == tencent_num or youyu_num in tencent_num: data.append( [item, youyu_num, tencent_num, basicConfig.test_pass]) else: data.append( [item, youyu_num, tencent_num, basicConfig.test_fail]) queue.put({ "stock_market": stock_market, "stock_code": stock_code, "stock_type": "", "result": util.test_result(data), "data": data }) return data
def parser_futu_basic(stock_market, stock_code): response = futu.futu_basic(stock_market, stock_code) data = {} compare_data = basicConfig.compare_other_data if util.check_error_code(response["code"]): for item in compare_data: data[item] = response["code"] else: try: temp_data = response.get("data").get("quote") temp_list = ["open_price", "last_price", "highest_price", "lowest_price", "volume", "turnover", "price"] for i in range(len(compare_data)): data[compare_data[i]] = temp_data.get(temp_list[i]) except: for item in compare_data: data[item] = basicConfig.ParserError.get("data") return data
def parser_yff_finance(env, stock_market, stock_code): yff = youyu.yff_stock_finance(env, stock_market, stock_code) data = {} for key in basicConfig.finance_hk: data.setdefault(key, "0.00") compare_data = basicConfig.finance_hk if util.check_error_code(yff.get("code")): for item in compare_data: data[item] = basicConfig.ResponseError.get("data") else: try: yff_result = yff.get("data") for result in yff_result: result_data = result.get("data") for result_item in result_data: data[result_item.get("title")] = result_item.get("value") except: for item in compare_data: data[item] = basicConfig.ParserError.get("data") return data