Administrator
2022-10-08 b55677003b3c81a35791e01f5f94d5b85f8d9b4a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
"""
同花顺行业工具
"""
 
# 同花顺行业
import global_util
import mongo_data
 
 
# 获取行业映射
def get_code_industry_maps():
    __code_map = {}
    __industry_map = {}
    results = mongo_data.find("ths-industry-codes", {})
    for r in results:
        code = r["_id"]
        industry = r["second_industry"]
        __code_map[code] = industry
        if __industry_map.get(industry) is None:
            __industry_map[industry] = set()
        __industry_map[industry].add(code)
    return __code_map, __industry_map
 
 
# 设置行业热度
def set_industry_hot_num(limit_up_datas):
    industry_hot_dict = {}
    code_industry_map = global_util.code_industry_map
    if code_industry_map is None or len(code_industry_map) == 0:
        global_util.load_industry();
        code_industry_map = global_util.code_industry_map
    if code_industry_map is None:
        raise Exception("获取代码对应的行业出错")
 
    for data in limit_up_datas:
        code = data["code"]
        industry = code_industry_map.get(code)
        if industry is None:
            # 获取代码对应的行业出错
            continue
        if industry_hot_dict.get(industry) is None:
            industry_hot_dict.setdefault(industry, 0)
 
        percent = float(data["limitUpPercent"])
        if percent > 21:
            percent = 21
        industry_hot_dict[industry] = round(industry_hot_dict[industry] + percent, 2)
 
    global_util.industry_hot_num = industry_hot_dict
 
 
if __name__ == "__main__":
    _code_map, _industry_map = get_code_industry_maps()
    print(_code_map, _industry_map)