-
Notifications
You must be signed in to change notification settings - Fork 1
/
sat_util.py
80 lines (67 loc) · 1.75 KB
/
sat_util.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
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
import datetime
import time
debug = False
#debug = True
def ToGB(s):
if(debug): print(s)
return s.decode('gbk') #gb2312
def ToUTF8(s):
if(debug): print(s)
return s.decode('utf8')
def ToUTF16(s):
if(debug): print(s)
return s.decode('utf16')
def suffix2prefix(code):
if (len(code)>=9):
fix =code[7:9].lower()
code = fix + code[0:6]
return code
def prefix2suffix(code):
if (len(code)>=8):
fix =code[0:2].upper()
code = code[2:8] + '.' + fix
return code
def codeAddPrefix(code):
if (len(code)<=6):
if (code[0]=='0'):
return 'sz'+code
elif (code[0]=='6'):
return 'sh'+code
else:
return 'sz'+code
return code
def codeAddSuffix(code):
if (len(code)<=6):
if (code[0]=='0'):
return code + 'sz'
elif (code[0]=='6'):
return code + 'sh'
else:
return code + 'sz'
return code
codesfile="util/A8.csv"
#code source file way 1
def GetAllCodesFromCSV():
import csv
c = csv.reader(open(codesfile,encoding='utf8'))
codes=[]
for id, code, name in c:
if id != 'NULL':
codes.insert(0, id)
elif code:
codes.insert(0, code[:6])
if (debug): print(code)
return codes
#创建csv文件名称
def CreateFileNameByDate(fPrefix, dtEnd, dtStart):
return fPrefix + dtEnd.strftime("%Y%m%d")+'_'+dtStart.strftime("%Y%m%d") + '.csv'
if __name__ == '__main__':
start = time.time()
codes=['601398']
print(codeAddPrefix(codes[0]))
codes = GetAllCodesFromCSV()
print(len(codes), codes)
end = time.time()
print("ms %d" %(end - start))