Administrator
2023-07-06 6a17f46b2b644e24786adbdcea64143a7ea166d6
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
import json
from datetime import datetime
 
import requests
 
 
def get_data(day):
    url = f"https://flash-api.xuangubao.cn/api/surge_stock/stocks?date={day.replace('-', '')}&normal=true&uplimit=true"
    result = requests.get(url)
    result = result.content.decode('utf-8')
    result = json.loads(result)
    if result['code'] != 20000:
        raise Exception("获取失败")
    items = result["data"]["items"]
    block_codes = {}
    for item in items:
        # 代码名称,几天几板,现价,涨幅,涨停时间,换手,自由市值
        data = [(item[1], item[0]), item[11], item[2], item[3], item[6], item[10], item[4]]
        # 转换格式
        data[3] = f"{'+' if data[3] > 0 else '-'}" + f"{round(data[3] * 100,2)}%"
        if data[4] > 0:
            data[4] = datetime.fromtimestamp(data[4]).strftime("%H:%M:%S")
        else:
            data[4] = '--'
        data[5] = f"{round(data[5] * 100, 2)}%"
        data[6] = f"{round(data[6] / 100000000, 2)}亿"
 
        blocks = []
        for b in item[8]:
            blocks.append(b['name'])
        for b in blocks:
            if b not in block_codes:
                block_codes[b] = []
            block_codes[b].append(data)
 
    return block_codes
 
 
if __name__ == '__main__':
    pass