-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathcsvv.py
More file actions
executable file
·80 lines (69 loc) · 2.21 KB
/
csvv.py
File metadata and controls
executable file
·80 lines (69 loc) · 2.21 KB
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
# -*- coding: utf-8 -*-
"""
功能:抓取個股殖利率程式
網址: http://www.twse.com.tw/ch/trading/exchange/BWIBBU/BWIBBU_d.php
前置作業:需要把csv檔中頭尾相關中文標題先刪除
"""
import csv
def yields():
"""
回傳dict:[股票名稱, 本益比, 殖利率(%), 股價淨值比]
回傳dict:[台泥utf8, '14.93', '5.69', '1.37']
EX: a['1101'] = [u'\u53f0\u6ce5', '14.93', '5.69', '1.37']
"""
twse_yields = {}
f = open('/home/tim/Stock_Bot/update_csv/BWIBBU_d20160331.csv','r')
for row in csv.reader(f):
try:
twse_yields[row[0]]=[row[1].decode('Big5'),row[2],row[3],row[4]]
except:
pass
f.close()
return twse_yields
def yields_otc():
"""
https://www.tpex.org.tw/web/stock/aftertrading/peratio_analysis/pera.php?l=zh-tw
回傳dict:[股票名稱, 本益比, 殖利率(%), 股價淨值比]
回傳dict:[台泥utf8, '14.93', '5.69', '1.37']
EX: a['1101'] = [u'\u53f0\u6ce5', '14.93', '5.69', '1.37']
"""
twse_yields = {}
f = open('/home/tim/Stock_Bot/update_csv/pera_1060706.csv','r')
for row in csv.reader(f):
try:
twse_yields[row[0]]=[row[1].decode('Big5'),row[2],row[4],row[5]]
except:
pass
f.close()
return twse_yields
def vip_other():
"""
回傳dict:[持股資料年度 政府機構() 僑外投資() 本國金融機構() 本國法人() 本國個人()]
"""
vip_other_return = {}
f = open('/home/tim/Stock_Bot/update_csv/Vip_others.csv','r')
for row in csv.reader(f):
try:
vip_other_return[row[1]]=[row[3],row[4],row[5],row[6],row[7],row[8]]
except:
pass
f.close()
return vip_other_return
def vip_main():
"""
回傳dict:[名稱 持股資料月份 全體董監持股(%) 全體董監質押(%) ]
"""
vip_main_return = {}
f = open('/home/tim/Stock_Bot/update_csv/Vip_main.csv','r')
for row in csv.reader(f):
try:
vip_main_return[row[0]]=[row[1],row[2],row[3],row[4]]
except:
pass
f.close()
return vip_main_return
if __name__ == "__main__":
a = vip_main()
print a['1101']
b = yields_otc()
print b['1258']