-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
52 lines (43 loc) · 1.67 KB
/
main.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
import getStockThree as three
import datetime
import time
import pandas as pd
now = datetime.datetime.now()
def getNewThree():
fail = True
date = now
while fail:
dateStr=date.strftime("%Y%m%d")
threeList = three.getThree(dateStr)
if(len(threeList['data'])!=0):
df = pd.DataFrame(threeList['data'],columns=threeList['fields'])
pd.set_option('display.unicode.ambiguous_as_wide', True)
pd.set_option('display.unicode.east_asian_width', True)
fail = False
print('========================='+ date.strftime("%Y%m%d")+ '=========================')
print(df)
else:
print(dateStr + '抓取失敗')
time.sleep(3) # 五秒內只能call三次 否則會被鎖
date = date - datetime.timedelta(days=1)
def getDateThree(date):
fail = True
while fail:
three.getThree(date)
date = date - datetime.timedelta(days=1)
time.sleep(3) # 五秒內只能call三次 否則會被鎖
def getStockDetail():
stockNumList = ['2330','2454','2337','2303']
stockList = []
fields = []
for stockNum in stockNumList:
tStart = time.time()#計時開始
stockData = three.getThreeBuyDetail(now, stockNum)
stockList.extend([[stockNum,"抓取時間:%f 秒" % (time.time() - tStart)]])
stockList.extend(stockData['data'])
fields=stockData['fields']
time.sleep(3) # 五秒內只能call三次 否則會被鎖
df = pd.DataFrame(stockList,columns=fields)
pd.set_option('display.unicode.ambiguous_as_wide', True)
pd.set_option('display.unicode.east_asian_width', True)
print(df)