-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathword.stock.py
executable file
·100 lines (80 loc) · 2.14 KB
/
word.stock.py
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python
import akshare as ak
from util.half import half
from os.path import dirname, abspath, basename
from tzutil.cout import cout
from time import sleep
def format_a(name):
return half(name.replace(' ', '').replace("*", '')).lower()
class Name:
def __init__(self):
self.exist = set()
def __str__(self):
r = []
for i in sorted(self.exist):
r.append(i)
return "\n".join(r)
def __lshift__(self, name):
name = name.strip().lower()
if name and name not in self.exist:
print(name)
self.exist.add(name)
NAME = Name()
class StockA:
def __init__(self):
self.exist = set()
def __call__(self, code, name):
name = format_a(name)
NAME << name
if code not in self.exist:
self.exist.add(code)
cout.green << (code, name)
sleep(3)
for i in range(999):
try:
li = ak.stock_info_change_name(stock=code) or []
except Exception as err:
print(err)
sleep(60)
else:
for i in li:
i = format_a(i)
if i[0] in "g" or "(" in i or (
i.startswith("s") and not i.startswith("st")
):
continue
NAME << i
return
def main():
outfile = abspath(__file__)[:-2] + "txt"
with open(outfile) as f:
for i in f:
i = i.strip("\n")
if i:
NAME << i
# 港股、美股
for func,attr in (
(ak.stock_us_spot, 'cname'),
(ak.stock_hk_spot,'name'),
):
li = func()
for index, i in li.iterrows():
name = i[attr].split("-")[0].replace("(", "(").split("(")[0]
if name.isascii():
continue
if name.endswith("公司"):
name = name[:-2]
if name.endswith("类股") or ' ' in name or '&#' in name:
continue
NAME << name
# A股全部
stock_a = StockA()
li = ak.stock_info_a_code_name()
for index, i in li.iterrows():
stock_a(i['code'], i['name'])
li = ak.stock_info_sz_delist(indicator="终止上市公司")
for index, i in li.iterrows():
stock_a(i['证券代码'], i['证券简称'])
with open(outfile, "w") as out:
out.write(str(NAME))
main()