diff options
Diffstat (limited to 'python/download_daily.py')
| -rw-r--r-- | python/download_daily.py | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/python/download_daily.py b/python/download_daily.py index 97b76595..51cb17ba 100644 --- a/python/download_daily.py +++ b/python/download_daily.py @@ -5,29 +5,46 @@ from ftplib import FTP import gnupg
import config
import sys
-import pdb
+import re
if os.name =='nt':
root = "//WDsentinel/share/Daily"
elif os.name == 'posix':
root = '/home/share/Daily'
+def get_ped(s):
+ regex = re.search("PED=(.+?)\.", s)
+ if regex:
+ PED = datetime.datetime.strptime(regex.group(1), "%Y-%m-%d").date()
+ else:
+ regex = re.search("(.+?)\.", s)
+ PED = datetime.datetime.strptime(regex.group(1), "%Y%m%d").date() - \
+ datetime.timedelta(1)
+ return PED
+
+def key_fun(s):
+ PED = get_ped(s)
+ regex = re.search("KD=(.+?)\.", s)
+ if regex:
+ KD = datetime.datetime.strptime(regex.group(1), "%Y-%m-%d-%H-%M-%S")
+ else:
+ regex = re.search("(.+?\..+?)\.", s)
+ KD = datetime.datetime.strptime(regex.group(1), "%Y%m%d.%H%M%S")
+ return (PED, KD)
+
def download_data(workdate):
ftp = FTP('ftp.globeop.com')
ftp.login('srntsftp', config.ftp_password)
ftp.cwd('outgoing')
files = ftp.nlst()
- globeopdate = datetime.date.strftime(workdate, '%Y%m%d')
-
pnlfiles = [filename for filename in files if "csv" in filename and \
- globeopdate in filename and \
- "Profit" in filename]
+ "Profit" in filename if get_ped(filename) < workdate]
valuationfiles = [filename for filename in files if "csv" in filename and \
- globeopdate in filename and \
- "Valuation" in filename]
- pnlfile = sorted(pnlfiles, reverse=True)[0]
- valuationfile = sorted(valuationfiles, reverse=True)[0]
+ "Valuation" in filename if get_ped(filename) < workdate]
+
+ pnlfile = sorted(pnlfiles, key=key_fun, reverse=True)[0]
+ valuationfile = sorted(valuationfiles, key=key_fun, reverse=True)[0]
if pnlfile:
if not os.path.exists(os.path.join(root, str(workdate), "Reports")):
|
