-
Notifications
You must be signed in to change notification settings - Fork 0
/
dtop.py
executable file
·44 lines (32 loc) · 1.11 KB
/
dtop.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
#!/usr/bin/python
"""dtop.py: Download the missing dtop zip files"""
import os
from hkex import Hkex
from datetime import date, timedelta
def getLatestDate(market, folder):
"""Get the list of files, and determine the latest date
Keyword arguments:
market -- stockOption / indexFuture
folder -- the storage folder
"""
if market == 'stockOption':
m = 'DTOP_O_'
elif market == 'indexFuture':
m = 'DTOP_F_'
dateList = []
# get file list from directory
for f in os.listdir(folder):
if m in f:
# crop the date from filename
row = f.replace(m,'').replace('.zip','')
dateList.append(date(int(row[:4]), int(row[4:6]), int(row[6:])))
latest = dateList[0]
for x in range(1,len(dateList)):
if dateList[x] > latest:
latest = dateList[x]
return latest
folder = './storage'
today = date.today()
downloader = Hkex()
downloader.fetchDtop('stockOption', getLatestDate('stockOption',folder), today)
downloader.fetchDtop('indexFuture', getLatestDate('indexFuture',folder), today)